0

I have a Drupal 8 form with checkboxes. The form submits upon clicking on a checkbox using JQuery.

Here is my code.

 $('#edit-event-types input[type=checkbox]').on('change', function(event, ui){
    $('#events-to-doc').submit();
  })

Unfortunately, if there isn't any submit button in the form, then function submitForm in the form class doesn't execute. But I don't need in a submit button on the form, I want to submit the form clicking on the checkboxes.

Can I somehow set the checkboxes element as the triggering element with Jquery? I need the function submitForm to execute and $form_state->getTriggeringElement() return the checkboxes as the triggering element.

1 Answer 1

2

Submit buttons (and their names) are special for Drupal. I'm not sure how this changed in D8, but in D7, the submit button name was used (IIRC) to determine which one was clicked.

I would suggest adding the submit button, hiding it with CSS and triggering a .click() to the button instead of doing .submit() directly. You can then either get the checkbox value if that's enough, or use a hidden field and some JS to determine which checkbox triggered the submit event (last clicked checkbox).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.