0

I'm using a CTools modal to add a holiday. The topside of that form in the modal displays the already defined holidays with an "X" that will allow you to delete a holiday. I have created a submit button for each that is put in a table with this code (the rows are rendered in a table afterwards).

foreach ($locationVO->Holidays as $holiday) {
    $fid = 'delete' . $holiday['id'];
    $form['holidays'][$fid] =
            array(
                '#name' => 'delete_' . $holiday['id'],
                '#type' => 'image_button',
                '#src' => $crossimg,
                '#attributes' => array('class' => array('delete_holiday')),
                '#return_value' => $holiday['id']
    );
   $field = drupal_render($form['holidays'][$fid]);

   $rows[] = array($holiday['name'], ISOdate2DutchDate($holiday['from']), ISOdate2DutchDate($holiday['to']), $field);
  }

Everything is rendered ok, but if I try to delete a holiday, the triggering_element and the clicked_button arrays in form_state still always refer to the main submit that I defined in the CTools form_info array. I therefor cannot distinguish between the submits for adding and deleting.

What do I need to do to get my triggering_element to correspond with the selected submit? I also tried specifying a separate '#submit' handler for the delete buttons, but that is never called either.

Other solutions are welcome as well, as long a I can do it without closing/leaving the modal (I already tried with a link to a separate delete handler which worked up until the referral back to the modal).

Thanks!

0

Never figured out how to do this, but I worked around the problem by using CTools functionality. In a nutshell I used ctools_ajax_image_button in the table, specified a specific callback for the url and then alter the table with ajax_command_remove, ajax_command_restripe and finally returning it with ajax_render.

This is all based on the CTools AJAX example that deletes rows from a table.

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.