My knowledge only reaches as far as setting a default value in an XML-SmartForm.
That you can do in the <PARAMETER> element with the code:
<VAR name = "value" value = "0" />
where the value correspond to the desired valu in the <DIRECTIVE> element. For example:
<DIRECTIVE KEY="optionList">
<VAR name = "0" value="Option 1" />
<VAR name = "1" value="Option 2" />
<VAR name = "2" value="Option 3" />
<VAR name = "3" value="Option 4" />
</DIRECTIVE>
Hope this helps in some way.
I will look and see if I can find any way of add a directive within the module, have to get back to you on that one, (if the pro's doesn't beat me to it).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, this was really simple...don't know how I missed it in the docs:
In the above example, the add line would look like:
$thisSelect =& $myForm->add('sex','Sex','select',true,'Female',array('multiple'=>true));
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes and in addition, for a Multiple select entity, you can set the items to be selected by passing the selected values as either a comma delimited list, or an array:
How do you choose which item is selected by default in a select list. Same question for choosing the checked options in a checkbox or radio buttons?
My knowledge only reaches as far as setting a default value in an XML-SmartForm.
That you can do in the <PARAMETER> element with the code:
<VAR name = "value" value = "0" />
where the value correspond to the desired valu in the <DIRECTIVE> element. For example:
<DIRECTIVE KEY="optionList">
<VAR name = "0" value="Option 1" />
<VAR name = "1" value="Option 2" />
<VAR name = "2" value="Option 3" />
<VAR name = "3" value="Option 4" />
</DIRECTIVE>
Hope this helps in some way.
I will look and see if I can find any way of add a directive within the module, have to get back to you on that one, (if the pro's doesn't beat me to it).
After going through some code, I found one way to this.
If yo add a select list like this for example:
$thisSelect =& $myForm->add('sex','Sex','select',true,'',array('multiple'=>true));
And then add some options.
$thisSelect->addOption("Male","Male");
$thisSelect->addOption("Female","Female");
$thisSelect->addOption("Something Inbetween","NULL");
You could then set the default option with.
$thisSelect->value = "Female";
Don't know if its the right way of doing it but it worked when I did a quick test.
Both my examples are with select lists. Have to get back to you with some examples of checkboxes and radiobuttons.
Any progress on the checkBoxes and radioButtons? That is, after adding a checkBoxEntity to a SmartForm, how do I set it to be checked!
Thanks!
Ok, this was really simple...don't know how I missed it in the docs:
In the above example, the add line would look like:
$thisSelect =& $myForm->add('sex','Sex','select',true,'Female',array('multiple'=>true));
yes and in addition, for a Multiple select entity, you can set the items to be selected by passing the selected values as either a comma delimited list, or an array:
$thisSelect =& $myForm->add('sex','Sex','select',true,'Female.Male',array('multiple'=>true));
or
$thisSelect =& $myForm->add('sex','Sex','select',true,array('Female','Male'),array('multiple'=>true));
shannon
Well, I missed that one too. Nice to know.
A sample for checkBoxes:
$value = 1; // or 0;
$eCB =& $myForm->add('myCheckBox', 'True?', 'checkBox', false, $value);
$eCB->addOption('', 1);