Miva Merchant Development by Scot's Scripts

FORM: Select/Options Function

Miva Knowledge Base
FORM: Select/Options Function
Important Notice: This information is for internal reference only. Use at your own risk.
Does Google actually understand your Miva Merchant store? Our JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

FORM: Select/Options Function

Scot Ranney • December 19, 2023


If you have a module or script with SELECTS and lots of options that need to be saved, this function can be quite useful. Gets rid of all the manual work.

<MvCOMMENT>
|
|  select is an easy way to deal with selections.
select:
	name: name of select form item '_fname'
	condition: the variable to match for a preselected item - actual variable value: l.info:fname
	options: 
		optionval1-Option Words 1,optionval2-Option Words 2,etc
	class: 'form-control'
	id: 'my-id'
	null_off: 1/0 - if null off then there is no "make a select" and it starts with the first option
	flags: anything like style="color: #ddd" or disabled, whatever you want to add to the select tag
	
<MvASSIGN NAME = "l.ok" VALUE = "{ select('_schedule:type',l.schedule:type,'optionval1-options words,optionval2-options words','form-select','schedule-type',1,'') }" />
|
</MvCOMMENT>

<MvFUNCTION NAME = "select" PARAMETERS = "name,condition,options,class,id,null_off,flags" STANDARDOUTPUTLEVEL="compresswhitespace,text,html">
	<MvASSIGN NAME = "l.options" VALUE = "{ miva_array_deserialize( l.options ) }" />
	<MvEVAL EXPR = "{ '<select class="' $ l.class $ '" id="' $ l.id $ '" name="' $ l.name $ '" ' $ l.flags $ '>' }">
		<MvIF EXPR = "{ NOT l.null_off }">
			<option value="">select...</option>
		</MvIF>
		<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>

https://www.scotsscripts.com/mvblog/selectoptions-function.html

mvkb_mivascript mvkb_select