Commit 6936c06d authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Andreas Fernandez
Browse files

[BUGFIX] Ensure manually updated slug is saved correctly

This fixes the bug, that after updating the slug and clicking
the toggle URL button, the slug isn't updated correctly.

Therefore, if the value of the input and read only field differ
after clicking the toggle button, now the updated value
of the input field is written into the read only and hidden field.

Furthermore after recreating the slug, the new value is now also
written into the input field to be present after clicking
the toogle URL button again. Otherwise the recreated slug would be
discarded on save.

Resolves: #86664
Releases: master, 9.5
Change-Id: I1cd8652618a7c5f2f7154c499ef1653bfed73c53
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61482


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarJens Ulrich <jens.ulrich@snk.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarJens Ulrich <jens.ulrich@snk.de>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent f571016b
......@@ -120,20 +120,25 @@ class SlugElement {
});
// Clicking the toggle button toggles the read only field and the input field.
// Also set the value of either the read only or the input field to the hidden field.
// Also set the value of either the read only or the input field to the hidden field
// and update the value of the read only field after manual change of the input field.
$(this.$fullElement).on('click', Selectors.toggleButton, (e): void => {
e.preventDefault();
const showReadOnlyField = this.$readOnlyField.hasClass('hidden');
this.$readOnlyField.toggleClass('hidden', !showReadOnlyField);
this.$inputField.toggleClass('hidden', showReadOnlyField);
if (showReadOnlyField) {
if (!showReadOnlyField) {
this.$hiddenField.val(this.$inputField.val());
return;
}
if (this.$inputField.val() !== this.$readOnlyField.val()) {
this.$readOnlyField.val(this.$inputField.val());
} else {
this.manuallyChanged = false;
this.$hiddenField.val(this.$readOnlyField.val());
this.$fullElement.find('.t3js-form-proposal-accepted').addClass('hidden');
this.$fullElement.find('.t3js-form-proposal-different').addClass('hidden');
} else {
this.$hiddenField.val(this.$inputField.val());
}
this.$hiddenField.val(this.$readOnlyField.val());
});
}
......@@ -181,6 +186,7 @@ class SlugElement {
if (mode === ProposalModes.AUTO || mode === ProposalModes.RECREATE) {
this.$readOnlyField.val(response.proposal);
this.$hiddenField.val(response.proposal);
this.$inputField.val(response.proposal);
} else {
this.$hiddenField.val(response.proposal);
}
......
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","jquery"],function(e,l,n){"use strict";var t,i,d,s;return(i=t||(t={})).toggleButton=".t3js-form-field-slug-toggle",i.recreateButton=".t3js-form-field-slug-recreate",i.inputField=".t3js-form-field-slug-input",i.readOnlyField=".t3js-form-field-slug-readonly",i.hiddenField=".t3js-form-field-slug-hidden",(s=d||(d={})).AUTO="auto",s.RECREATE="recreate",s.MANUAL="manual",function(){function e(e,l){var i=this;this.options=null,this.$fullElement=null,this.manuallyChanged=!1,this.$readOnlyField=null,this.$inputField=null,this.$hiddenField=null,this.xhr=null,this.fieldsToListenOn={},this.options=l,this.fieldsToListenOn=this.options.listenerFieldNames||{},n(function(){i.$fullElement=n(e),i.$inputField=i.$fullElement.find(t.inputField),i.$readOnlyField=i.$fullElement.find(t.readOnlyField),i.$hiddenField=i.$fullElement.find(t.hiddenField),i.registerEvents()})}return e.prototype.registerEvents=function(){var e=this,l=Object.keys(this.getAvailableFieldsForProposalGeneration()).map(function(l){return e.fieldsToListenOn[l]});l.length>0?("new"===this.options.command&&n(this.$fullElement).on("keyup",l.join(","),function(){e.manuallyChanged||e.sendSlugProposal(d.AUTO)}),n(this.$fullElement).on("click",t.recreateButton,function(l){l.preventDefault(),e.$readOnlyField.hasClass("hidden")&&(e.$readOnlyField.toggleClass("hidden",!1),e.$inputField.toggleClass("hidden",!0)),e.sendSlugProposal(d.RECREATE)})):n(this.$fullElement).find(t.recreateButton).addClass("disabled").prop("disabled",!0),n(this.$inputField).on("keyup",function(){e.manuallyChanged=!0,e.sendSlugProposal(d.MANUAL)}),n(this.$fullElement).on("click",t.toggleButton,function(l){l.preventDefault();var n=e.$readOnlyField.hasClass("hidden");e.$readOnlyField.toggleClass("hidden",!n),e.$inputField.toggleClass("hidden",n),n?(e.manuallyChanged=!1,e.$hiddenField.val(e.$readOnlyField.val()),e.$fullElement.find(".t3js-form-proposal-accepted").addClass("hidden"),e.$fullElement.find(".t3js-form-proposal-different").addClass("hidden")):e.$hiddenField.val(e.$inputField.val())})},e.prototype.sendSlugProposal=function(e){var l=this,t={};e===d.AUTO||e===d.RECREATE?n.each(this.getAvailableFieldsForProposalGeneration(),function(e,l){t[e]=n('[data-formengine-input-name="'+l+'"]').val()}):t.manual=this.$inputField.val(),null!==this.xhr&&4!==this.xhr.readyState&&this.xhr.abort(),this.xhr=n.post(TYPO3.settings.ajaxUrls.record_slug_suggest,{values:t,mode:e,tableName:this.options.tableName,pageId:this.options.pageId,parentPageId:this.options.parentPageId,recordId:this.options.recordId,language:this.options.language,fieldName:this.options.fieldName,command:this.options.command,signature:this.options.signature},function(n){n.hasConflicts?(l.$fullElement.find(".t3js-form-proposal-accepted").addClass("hidden"),l.$fullElement.find(".t3js-form-proposal-different").removeClass("hidden").find("span").text(n.proposal)):(l.$fullElement.find(".t3js-form-proposal-accepted").removeClass("hidden").find("span").text(n.proposal),l.$fullElement.find(".t3js-form-proposal-different").addClass("hidden")),l.$hiddenField.val()!==n.proposal&&l.$fullElement.find("input").trigger("change"),e===d.AUTO||e===d.RECREATE?(l.$readOnlyField.val(n.proposal),l.$hiddenField.val(n.proposal)):l.$hiddenField.val(n.proposal)},"json")},e.prototype.getAvailableFieldsForProposalGeneration=function(){var e={};return n.each(this.fieldsToListenOn,function(l,t){n('[data-formengine-input-name="'+t+'"]').length>0&&(e[l]=t)}),e},e}()});
\ No newline at end of file
define(["require","exports","jquery"],function(e,l,n){"use strict";var i,t,d,s;return(t=i||(i={})).toggleButton=".t3js-form-field-slug-toggle",t.recreateButton=".t3js-form-field-slug-recreate",t.inputField=".t3js-form-field-slug-input",t.readOnlyField=".t3js-form-field-slug-readonly",t.hiddenField=".t3js-form-field-slug-hidden",(s=d||(d={})).AUTO="auto",s.RECREATE="recreate",s.MANUAL="manual",function(){function e(e,l){var t=this;this.options=null,this.$fullElement=null,this.manuallyChanged=!1,this.$readOnlyField=null,this.$inputField=null,this.$hiddenField=null,this.xhr=null,this.fieldsToListenOn={},this.options=l,this.fieldsToListenOn=this.options.listenerFieldNames||{},n(function(){t.$fullElement=n(e),t.$inputField=t.$fullElement.find(i.inputField),t.$readOnlyField=t.$fullElement.find(i.readOnlyField),t.$hiddenField=t.$fullElement.find(i.hiddenField),t.registerEvents()})}return e.prototype.registerEvents=function(){var e=this,l=Object.keys(this.getAvailableFieldsForProposalGeneration()).map(function(l){return e.fieldsToListenOn[l]});l.length>0?("new"===this.options.command&&n(this.$fullElement).on("keyup",l.join(","),function(){e.manuallyChanged||e.sendSlugProposal(d.AUTO)}),n(this.$fullElement).on("click",i.recreateButton,function(l){l.preventDefault(),e.$readOnlyField.hasClass("hidden")&&(e.$readOnlyField.toggleClass("hidden",!1),e.$inputField.toggleClass("hidden",!0)),e.sendSlugProposal(d.RECREATE)})):n(this.$fullElement).find(i.recreateButton).addClass("disabled").prop("disabled",!0),n(this.$inputField).on("keyup",function(){e.manuallyChanged=!0,e.sendSlugProposal(d.MANUAL)}),n(this.$fullElement).on("click",i.toggleButton,function(l){l.preventDefault();var n=e.$readOnlyField.hasClass("hidden");e.$readOnlyField.toggleClass("hidden",!n),e.$inputField.toggleClass("hidden",n),n?(e.$inputField.val()!==e.$readOnlyField.val()?e.$readOnlyField.val(e.$inputField.val()):(e.manuallyChanged=!1,e.$fullElement.find(".t3js-form-proposal-accepted").addClass("hidden"),e.$fullElement.find(".t3js-form-proposal-different").addClass("hidden")),e.$hiddenField.val(e.$readOnlyField.val())):e.$hiddenField.val(e.$inputField.val())})},e.prototype.sendSlugProposal=function(e){var l=this,i={};e===d.AUTO||e===d.RECREATE?n.each(this.getAvailableFieldsForProposalGeneration(),function(e,l){i[e]=n('[data-formengine-input-name="'+l+'"]').val()}):i.manual=this.$inputField.val(),null!==this.xhr&&4!==this.xhr.readyState&&this.xhr.abort(),this.xhr=n.post(TYPO3.settings.ajaxUrls.record_slug_suggest,{values:i,mode:e,tableName:this.options.tableName,pageId:this.options.pageId,parentPageId:this.options.parentPageId,recordId:this.options.recordId,language:this.options.language,fieldName:this.options.fieldName,command:this.options.command,signature:this.options.signature},function(n){n.hasConflicts?(l.$fullElement.find(".t3js-form-proposal-accepted").addClass("hidden"),l.$fullElement.find(".t3js-form-proposal-different").removeClass("hidden").find("span").text(n.proposal)):(l.$fullElement.find(".t3js-form-proposal-accepted").removeClass("hidden").find("span").text(n.proposal),l.$fullElement.find(".t3js-form-proposal-different").addClass("hidden")),l.$hiddenField.val()!==n.proposal&&l.$fullElement.find("input").trigger("change"),e===d.AUTO||e===d.RECREATE?(l.$readOnlyField.val(n.proposal),l.$hiddenField.val(n.proposal),l.$inputField.val(n.proposal)):l.$hiddenField.val(n.proposal)},"json")},e.prototype.getAvailableFieldsForProposalGeneration=function(){var e={};return n.each(this.fieldsToListenOn,function(l,i){n('[data-formengine-input-name="'+i+'"]').length>0&&(e[l]=i)}),e},e}()});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment