How to limit selection on Multi select form Field

I am trying to limit the total number of items that can be selected on the $has_many multiselect form field, the user guide don't seem to provide a way to this. is there parameter for such feature like LIMIT on multi select form field.
$fields['multi_example'] = array('type' => 'multi', 'options' => $options, 'value' => 'a' , 'limit'=> some value);


  • There currently is not such an option to limit the selection.

  • What other approach can i use to achieve this. i have tried to inserd the disabled= true and readonly = true, attribute to the multiselect using javascript but it did not work.

    i want to disable selection once a user select a cirtain number of item

  • if it was me, I'd create a new custom field based on the multi field type and add javascript to count the selections on each change.
    Maybe there's already a similar selection widget out there that does that? Perhaps incorporate that as a custom field?

  • i tried that, the problem is that it wont just disable by adding the attribute disabled=yes or readonly= yes. they dont have effect on it.
    secondly it is suppose to be a has_many hook so i am not sure i can do that with custom field

  • edited January 2021

    Why just not hide (size 0 x 0) list using CSS and JS? So no more selections are possible if number of items > max number of items.

    If items have been removed, reverse procedure. I have not try, but will as it sounds like something what would be useful at some point.

    Just idea :)

Sign In or Register to comment.