0

I'm trying to do this:

echo $this->Form->input("filter.wijk", array(
    'onChange' => 'this.form.submit()', 
    'type' => 'select', 
    'multiple' => 'checkbox', 
    'options' => $wijkOpties, 
    'label' => false)
);

However, the onChange attribute does not appear in the resulting HTML. The documentation for FormHelper::input tells us this:

* ### Options
*
* See each field type method for more information. Any options that are part of
* $attributes or $options for the different **type** methods can be included in `$options` for input().i
* Additionally, any unknown keys that are not in the list below, or part of the selected type's options
* will be treated as a regular html attribute for the generated input.

Am I interpreting that last sentence in the wrong way?

2
  • Well I don't believe it's satisfied with the 'multiple' => 'checkbox', your code is just fine, it's simply that when the list is changed to multiple checkboxes list the onChange is not copied too ! Try 'multiple' => true, and your code will work fine just as stated in the documentation. Commented Oct 21, 2014 at 8:59
  • Thanks, that does work as far as the JavaScript is concerned, but now they are not checkboxes anymore and I really need checkboxes here. Commented Oct 21, 2014 at 9:14

1 Answer 1

1

You have 2 options:

1- Give up on the checkboxes and simply get a normal select list element/box:

echo $this->Form->input("filter.wijk", array(
                        'onChange' => 'this.form.submit()', 
                        'type' => 'select', 
                        'multiple' => true, 
                        'options' => $wijkOpties, 
                        'label' => false)
);

2- Do a workaround for a valid checkboxes list (Something like):

$i = 0;
foreach($wijkOpties as $value => $option){
    echo $this->Form->input('filter.wijk.' . $i++, array(
                                'onChange' => 'this.form.submit()',
                                'label' => $option,
                                'value' => $value,
                                'type' => 'checkbox',
    ));
}

`

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.