0

As I can't find a way to split a Drupal Commerce pane into several forms (so far it creates several field-sets) I had to create several submit buttons in the same form. But it's the same submit button that always gets triggered.

I have these 2 "forms":

- Field 1.1
- Field 1.2
-> Submit 1

- Field 2.1
->Submit 2

I believe this would not be a problem if I would not use ajax to submit the forms, but I do by using 'event' => 'click' so that the form is submited when ENTER is pressed.

My problem is that if I press ENTER from the field 2.1 it's the Submit 1 that gets triggered.

Any idea on how to select the right submit button with the click event?

0

My solution was to remove the Drupal click event:

'event' => 'click',

And to manually add it via jQuery by finding the next input button:

$('input.form-text', context).once('field_validation_keydown').keydown(function(event) {
  if (event.which == 13) {
    $(this).parent().nextAll('input.ajax-processed').trigger('mousedown');
  }
});

But if anyone has a better solution, I'm curious to know about it.

|improve this answer|||||
0

For every form element (button) add the #name property and it should be unique in that form

e.g.

$form['button_1'] = array(
    '#type' => 'button',
    '#name' => 'button_1',
...

$form['submit_1'] = array(
    '#type' => 'submit',
    '#name' => 'submit_1',
...
|improve this answer|||||

Your Answer

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

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