<xmod:select>

 

New to version 4.0

 

TEMPLATE CONTROL: This tag is only valid in list view and detail templates.

 

The <xmod:select> gives you a lot of flexibility in creating your display template. It is similar to the <xmod:if> tag but is much more flexible and powerful.  It's similar in function to Visual Basic's Select/Case statement and Javascript's switch/case statement. For non-programmer's you can think of it as a multiple choice tag.

 

The <xmod:select> tag contains one or more <case> tags and one optional <else> tag. At run-time, XMod will evaluate each <case> tag beginning with the first one in the list. If the tag doesn't evaluate to True, XMod moves to the next <case> tag and evaluates it. It continues this way until it reaches a true <case>. If none is found, then nothing will be displayed unless an <else> tag has been included. If so, it's contents will be displayed.

 

<xmod:select>

  <case value="1" operator="=" expression="2" comparetype="text">  1 = 2 </case>

  <case value="1" operator="=" expression="1" comparetype="text">  1 = 1 </case>

  <else>  No valid case statement found </else>

</xmod:select>

 

In the above example we're stating that IF "1" = "2" THEN display the text "1 = 2" in the first <case> statement.

The second <case> says IF "1" = "1" THEN display the text "1 = 1".

Finally, if neither of the <case> statements is true, then the text "No valid case statement found" will be displayed.

 

Since "1" = "1", then the result of the <xmod:select> tag is the display of the text "1 = 1"

 

Comparison Data Types:

Note that XMod's tests to see if the text "1" is the same as the text "1". XMod isn't comparing the values as numbers. It's comparing the values as text. However, that can easily be changed by using the <case> tag's comparetype attribute. Using this, you can tell XMod to compare the values as numeric values, floating point numbers, dates, boolean, text, or to see if the value matches a regular expression pattern. You can also compare whether the current user is/isn't in one or more security roles.

 

Operators

You're also not limited to just testing for equality. Using the operator attribute of the <case> tag, you can test for equality "=", inequality "<>", less-than "<", greater-than ">", less-than-or-equal "<=", and greater-than-or-equal ">=". Of course, these operators don't make sense for all types of comparisons. For instance, if you are doing a regular expression comparison, the value can either match or not-match the regular expression pattern. So, the only valid operators in that case are "=" and "<>".

 

Case-Sensitive Comparisons

If you're doing text comparisons, you can set the <case> tag's ignorecase attribute to "true" or "false" to tell the tag to perform a case-insensitive comparison (true) or a case-sensitive comparison (false).

 

Culturally-Sensitive Comparisons

Finally, the <case> tag includes a culture attribute. This can be set to an LCID (a culture ID) that will instruct the tag that comparisons should be made using the settings of that culture. If no culture tag is set, the tag will attempt to use the current culture.

NOTE: Boolean comparisons do not use a culture setting. Additionally, regular expressions use the system's culture by default. You cannot specify a culture for them. However, as with all comparisons, you can specify "invariant" as the culture to perform a culturally neutral comparison.

 

"Inclusive" Evaluation
The <xmod:select> tag provides one attribute: mode. Valid values for this attribute are "standard" and "inclusive". By default this is set to "standard".

standard: the <xmod:select> tag will evaluate all <case> tags until it finds one that evaluates to true. It will display that tag's contents and stop evaluating. If no true <case> tag is found and an <else> tag is found, then the contents of the <else> tag will be displayed.
inclusive:
ALL <case> tags will be evaluated. Any tags which evaluate to true will have their contents displayed. If an <else> tag is found, its contents will also be displayed.

 

 

ATTRIBUTES <xmod:select>:

mode

Determines how the tag will operate. Valid values are:
 

  • standard - the select will only display the contents of the first true <case> statement it encounters. If no true case statement is found, the tag will display the <else> tag's contents, if one has been specified. Otherwise, nothing is displayed.

  • inclusive- the select will display the contents of all true <case> statements it finds. If an <else> tag is specified, it will also be displayed.
     

This attribute is Optional. The default value is standard

 

ATTRIBUTES <case>:

value

This is the value that the tag will test. You can use <xmod:field> tags, <xmod:user> tags and other tags that return a value. If you use these dynamic-value tags, you should avoid setting properties such as the detaillink property of the <xmod:field> tag as that will interfere with the proper processing of the select tag. You can also hard-code the value. This attribute is REQUIRED unless the comparetype is "role".

expression

This is the expression that is used to test the value. This can be a hard-coded value, the value from an <xmod:field> or similar tag or a regular expression pattern (for regular expression comparisons). If comparetype is "role" then this attribute should contain a comma-delimited list of security role names. This attribute is REQUIRED

operator

Determines what kind of evaluation will be made. Valid values are:

 

  • = (equality)

  • < (less-than)

  • > (greater-than)

  • <> (not equal)

  • <= (less-than or equal-to)

  • >= (greater-than or equal-to)

 

Ex: value="1" expression="2" operator="<"  would translate to: 1 < 2.

 

The value property is always on the left side of the operator while the expression value is always on the right.

 

NOTE: Not all operators function for all types of comparisons. With regular expression comparisons, you can specify "=" for "Is A Match" or "<>" for "Is Not A Match", but the other operators have no relevance. If "<>" is not specified, then "=" is assumed.

 

This attribute is REQUIRED

comparetype

This allows you to tell the tag what type of data is being compared. Valid values are:

 

  • numeric - value and expression are treated as whole numbers

  • float - value and expression are treated as floating-point numbers

  • date - value and expression are treated as date/time values

  • text - value and expression are treated as text

  • regex - value is compared against the regular expression pattern in expression. Valid operators are "=" and "<>"

  • boolean - value and expression are treated as True/False values. When comparing numbers as booleans, 0 is False and all other numbers are True. Valid operators are "=" and "<>"

  • role - expression is treated as a comma-delimited list of security role names. value is ignored. Valid operators are "=" and "<>"

 

This attribute is REQUIRED

ignorecase

For text and regex comparison types, ignore case allows you to perform case-insensitive comparisons, so that "I" and "i" are the same.

This attribute is OPTIONAL. The default value for this is True.

culture

Valid values are: invariant or a valid LCID such as "en-GB" "fr" "de" etc. "invariant" results in a "neutral" culture. If the property is blank or not specified, culture defaults to the current system's culture.
 

USAGE:

  • For numeric, float and date types, this allows you to specify which culture to use when converting from text to the number/date.

  • For text comparisons, it allows you to specify a culture to use during the  comparison.

  • Boolean comparisons do not use a culture setting.

  • Regular expression comparisons use the system's culture by default. You cannot specify a specific culture for them. However, as with all comparisons, you can specify "invariant" as the culture to use "neutral" culture settings.
     

This attribute is OPTIONAL. If not specified, the culture default's to the current system settings.

 

ATTRIBUTES <else>:

The <else> tag has no attributes. Only one <else> tag is allowed but it is not required. When included, the <else> tag defines content that should be displayed in the event that no <case> tags evaluate to True (in standard mode). When the mode is set to "inclusive", the contents of the <else> tag will always be displayed.

This tag is OPTIONAL

 

EXAMPLE

This example compares the value of a form field to various know fruits.

 

<xmod:select>

  <case value="<xmod:field name="Fruit"/>" operator="=" expression="Apple" comparetype="text">

Your fruit is <span style="color:red;">RED</span>

  </case>

  <case value="<xmod:field name="Fruit"/>" operator="=" expression="Orange" comparetype="text">

Your fruit is <span style="color:orange;">ORANGE</span>

  </case>

  <case value="<xmod:field name="Fruit"/>" operator="=" expression="Blueberries" comparetype="text">

Your fruit is <span style="color:blue;">BLUE</span>

  </case>

  <else>

     You've chosen an unknown fruit

  </else>

</xmod:select>

 

If the record's "Fruit" field is "Apple" or "apple" (because ignorecase is true by default) then this will display:

Your fruit is RED

 

If the user chose "Orange" then:

Your fruit is ORANGE

 

If the user chose "Blueberries" then:

Your fruit is BLUE

 

If the user chose something else or nothing at all, then:

You've chosen an unknown fruit

 

 

This example looks for fruits entered via in a multi-select list box, called "Fruits". It's mode is set to inclusive so every true <case> tag will display in addition to the <else> tag. Since this is a list-type field, selected values are placed in a comma-delimited list like this:

 

Apple,Grapefruit,Orange,Grape,Watermelon,Blueberry

 

So, we can use a regular expression like "\bApple\b" to see if "Apple" is in the list. The "\b" represents a "word boundary" like the beginning or end of the line, punctuation, and white space.

 

<xmod:select mode="inclusive">

  <case value="<xmod:field name="Fruits"/>" operator="=" comparetype="regex" expression="\bApple\b">

    You like Apples<br>

  </case>

  <case value="<xmod:field name="Fruits"/>" operator="=" comparetype="regex" expression="\bOrange\b">

    You like Oranges<br>

  </case>

  <case value="<xmod:field name="Fruits"/>" operator="=" comparetype="regex" expression="\bBlueberry\b">

    You like Blueberries<br>

  </case>

  <case value="<xmod:field name="Fruits"/>" operator="=" comparetype="regex" expression="\bKiwi\b">

    You like Kiwis<br>

  </case>

  <case value="<xmod:field name="Fruits"/>" operator="<>" comparetype="regex" expression="\bCherry\b">

    You don't like Cherries<br>

  </case>

</xmod:select>

 

Given the list of selected values identified above, this tag would display:

You like Apples

You like Oranges

You like Blueberries

You don't like Cherries

 

Notice that it didn't find "Kiwi" so that line is not displayed. Also, the last <case> changes the operator to "<>" - meaning if there is no match. Since "Cherry" is not in the list, "You don't like cherries" is displayed.