You know when you are coding forms for editing data and they contain select/option drop downs? And sometimes they have lots of options and you need to make sure the right one is selected when populating the form with data?
For me this always meant a lot of MvIF statements in the options part of the select element. Not anymore.
Code:
<MvFUNCTION NAME = "select" PARAMETERS = "class,default,name,condition,options" STANDARDOUTPUTLEVEL="compresswhitespace,text,html" > <MvASSIGN NAME = "l.options" VALUE = "{ miva_array_deserialize( l.options ) }" /> <select class="{ l.class } name="{ l.name }"> <option value=""><MvEVAL EXPR = "{ l.default }"></option> <MvFOREACH ITERATOR = "l.option" INDEX = "l.pos" ARRAY = "l.options"> <MvIF EXPR = "{ gettoken(l.option,'-',1) EQ l.condition }"> <option value="{ gettoken(l.option,'-',1) }" selected><MvEVAL EXPR = "{ gettoken(l.option,'-',2) }"></option> <MvELSE> <option value="{ gettoken(l.option,'-',1) }"><MvEVAL EXPR = "{ gettoken(l.option,'-',2) }"></option> </MvIF> </MvFOREACH> </select> </MvFUNCTION>
The default parameter sets the no-value option (like, "Select one...")
The name parameter is the name of the variable for the "select" form element.
The condition parameter is the what has to match in order to make an option selected.
The options parameter is a list of option values and labels, set up like:
Code:
<MvASSIGN NAME = "l.options" VALUE = "{ 'value1-Option Label One,value2-Option Label Two,value3-Option Label Three,value4-Option Label Four' }" />
Code:
<MvASSIGN NAME = "l.ok" VALUE = "{ select(l.null,'Select one...','selected_value',l.null,l.options) }" />
Code:
<MvASSIGN NAME = "l.condition" VALUE = "{ 'value1' }" /> <MvASSIGN NAME = "l.ok" VALUE = "{ select(l.null,'Select one...','selected_value',l.condition,l.options) }" />
You could add "class" and "default option" parameters to set the select element class and the "null" option ("select one...") to really flesh it out.