How do I find how many options there are for a select field?
How do I find how many options there are for a select field?
I have the following field defined How do I get the number of options for the select? I'd like to hide the field if there is only 1.
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/PermissionToEnter.php',
table: '#PermissionToEnter',
fields: [
{
"label": "Unit",
"name": "PermissionToEnter.unit",
"type": "select2",
"opts": {
theme: "classic"
}
},
.
.
.
Thanks!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
There isn't an API built into Editor for that - however, it is quite possible with a little jQuery to get the number of options:
Allan
edit I've just realised you are using
select2
. This may or may not work in that case - I'm not 100% certain what select2 does with theselect
element.The following worked:
a parenthesis was missing after field.nide :)
Thanks again!!!