Search the Community
Showing results for tags 'InputfieldSelectMultiple'.
-
I am trying to get the "text Content" (not the value) portion of an InputfieldSelectMultiple property I created for an installed module. The selected options are saved in PW somewhere. How do I get at it? viz: <select name="fieldA"> <option selected value=0>Content 1</option> <option value=1>Content 2</option> <option selected value=2>Content 3</option> </select> I know its an array and that i'd have to access the options in a loop. But I can't seem to make the right call to any of the methods that return an array. So, here's an example of many that i tried and failed: $module = wire('modules')->get('ImportMyModule'); $field = $module->get('fieldA'); $options = $field->getOptions(); foreach($options as $key => $val) { echo "key: ", $key, " val: ", $val; } I can't figure out to get at just the "text Content" for now , then the selected one's after. (in the above sample "Content 1" and "Content 3") It'll save me a bunch of if's. Thanks forum!
-
Hello everybody, I am playing with the InputfieldSelectMultiple module, and I was wondering how to set the "selected" attribute for an Option? I have the following code: $field = $modules->get("InputfieldSelectMultiple"); $field->label = "Multiple select"; $field->attr('id+name', 'options'); $field->setAttribute('multiple', 'multiple'); $field->setAttribute('size', '8'); $field->addOption('121', '121-22', array('selected' => 'selected')); Which gives me this: <option selected='selected' selected="selected" value='121'>121-22</option> While it technically makes an option selected, this also produces redundant HTML code which does not validate. So, what's the right way to use addOption() so that the output is more like <option selected value=...> ? Thanks.