Determine count of items in an editor 'select' item
Determine count of items in an editor 'select' item
I'm showing a select list of items (MapCategory) that a Map item can belong too. I want to disable the Create button in the Map editor UI until the user has created at least one MapCategory item. How can I determine the count of MapCategory items on the client side.
A snippet of code from the Map editor looks as follows:
Editor::inst($db, 'Map', '_id')
->fields(
<snip><snip><snip>
Field::inst('Map._idCategory')
->options(Options::inst()
->table('MapCategory')
->value('_id')
->label('name')
)
->validator(Validate::dbValues()),
Field::inst('MapCategory.name'),
<snip><snip><snip>
)
->leftJoin('MapCategory', 'MapCategory._id', '=', 'Map._idCategory')
->process($_POST)
->json();
The MapCategory is shown using a 'Select' control on the client (JavaScript) side. I'd like to disable 'Create' button on Map table until at least one MapCategory has been created. How can I get the count of MapCategory items in the editor above?
This question has accepted answers - jump to:
Answers
On the client-side you could use
field().val()
to get the array and then get itslength
property - e.g.:Combine that with a little client-side validation and you can stop the user submitting until they've got at least one selected.
Allan
Hi @icefield ,
If you want to disable the button, you can do something like this - this disables the New Entry form's Create button until there is something in the "Office" field. Hope that helps,
Cheers,
Colin
Thank you both (Alan and Colin) very much. - Tom