0

I have added a markup which changes dynamically via jquery but on submission it validates and if there is a field level error like the title is missing it does not show the HTML which was dynamically added. How can I retain the HTML which is added in markup via js

The code in form is

$form[$field_name.'-fieldset'][$field_name.'-popup-data'] = array(
      '#type' => 'markup',
      '#markup' => t('<div id="'.$field_name.'-popup-data" class="popup-data" field="' . $field_name . '"></div>'),
      '#attributes' => array('field'=> $field_name),
      '#weight' => 10,
      '#language' => $language->language,
    );

In the JS I added dynamically the HTML value inside the popup-data class but it disappears during validation

  • Hey hey, please add the JS as well. – leymannx Jun 16 '18 at 6:00
  • It's because the jQuery can't update the $form variable. You have have to simulate a button press with jQuery for a submit element you could hide with css, that has an Ajax callback – jackrabbithanna Jun 16 '18 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.