From ce9416d887a03610197f738a837cf21c29bd4b2c Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 18 Dec 2018 11:08:54 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B01878=20Request=20Template:=20Fix=20histo?= =?UTF-8?q?ry=20updated=20even=20if=20template=20not=20updated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When editing the object, the hidden input is not initialized correctly with the values from the form. This is due to a timing issue among async processes. To fix that, we made sure the WizardHelper updates the input value before submit. The real fix would be to better handle the subform building process. --- application/cmdbabstract.class.inc.php | 41 +++++++++++++++----------- js/field_set.js | 1 + 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 0cdd19db7..58fcc339d 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -2075,11 +2075,6 @@ EOF $oRenderer = new \Combodo\iTop\Renderer\Console\ConsoleFormRenderer($oForm); $aRenderRes = $oRenderer->Render(); - $aFormHandlerOptions = array( - 'wizard_helper_var_name' => 'oWizardHelper'.$sFormPrefix, - 'custom_field_attcode' => $sAttCode, - ); - $sFormHandlerOptions = json_encode($aFormHandlerOptions); $aFieldSetOptions = array( 'field_identifier_attr' => 'data-field-id', // convention: fields are rendered into a div and are identified by this attribute @@ -2088,23 +2083,35 @@ EOF 'form_path' => $oForm->GetId(), ); $sFieldSetOptions = json_encode($aFieldSetOptions); + $aFormHandlerOptions = array( + 'wizard_helper_var_name' => 'oWizardHelper'.$sFormPrefix, + 'custom_field_attcode' => $sAttCode, + ); + $sFormHandlerOptions = json_encode($aFormHandlerOptions); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/form_handler.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/console_form_handler.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/field_set.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/form_field.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/subform_field.js'); - $oPage->add_ready_script("$('#{$iId}_console_form').console_form_handler($sFormHandlerOptions);"); - $oPage->add_ready_script("$('#{$iId}_field_set').field_set($sFieldSetOptions);"); - $oPage->add_ready_script("$('#{$iId}_console_form').console_form_handler('alignColumns');"); - $oPage->add_ready_script("$('#{$iId}_console_form').console_form_handler('option', 'field_set', $('#{$iId}_field_set'));"); - // field_change must be processed to refresh the hidden value at anytime - $oPage->add_ready_script("$('#{$iId}_console_form').bind('value_change', function() { $('#{$iId}').val(JSON.stringify($('#{$iId}_field_set').triggerHandler('get_current_values'))); });"); - // Initialize the hidden value with current state - $oPage->add_ready_script("$('#{$iId}_console_form').trigger('value_change');"); - // update_value is triggered when preparing the wizard helper object for ajax calls - $oPage->add_ready_script("$('#{$iId}').bind('update_value', function() { $(this).val(JSON.stringify($('#{$iId}_field_set').triggerHandler('get_current_values'))); });"); - // validate is triggered by CheckFields, on all the input fields, once at page init and once before submitting the form - $oPage->add_ready_script("$('#{$iId}').bind('validate', function(evt, sFormId) { return ValidateCustomFields('$iId', sFormId) } );"); // Custom validation function + $oPage->add_ready_script( +<<