From wiki.ginstr.com
Jump to: navigation, search
(Comparator types)
m (formatting)
Line 5: Line 5:
 
;Description
 
;Description
 
: It performs a comparison of content between two widgets.
 
: It performs a comparison of content between two widgets.
: IMPORTANT: this validator is not executing required check, if value in widget is null it will return true. You should add [[RequiredValidator]] as well to this widget if you need value entered.
+
: '''IMPORTANT:''' this validator is not executing required check, if value in widget is null it will return true. You should add <code>[[RequiredValidator]]</code> as well to this widget if you need value entered.
  
 
==Attributes==
 
==Attributes==
Line 15: Line 15:
 
! scope="col" | Description
 
! scope="col" | Description
 
|-
 
|-
| title="Attribute" | message<span style="color:red">*</span>
+
| title="Attribute" | <code>message</code><span style="color:red">*</span>
 
| title="Description" | Defines default message to be displayed when validation fails
 
| title="Description" | Defines default message to be displayed when validation fails
  
Line 21: Line 21:
 
* <code>@string</code>
 
* <code>@string</code>
 
|-
 
|-
| title="Attribute" | [[Widget_Library|targetWidget]]
+
| title="Attribute" | <code>[[Widget_Library|targetWidget]]</code>
| title="Description" | Defines target that will get compared to widget holding the validator. '''Validated widget and target have to be of same datatype in order to compare them successfully, with exception of equalLength comparation'''
+
| title="Description" | Defines target that will get compared to widget holding the validator.
 +
'''Validated widget and target have to be of same datatype in order to compare them successfully, with exception of <code>equalLength</code> comparator'''
 
* Valid [[target|targets]]:
 
* Valid [[target|targets]]:
 
** any [[target]]
 
** any [[target]]
 
|-
 
|-
| title="Attribute" | comparator
+
| title="Attribute" | <code>comparator</code>
 
| title="Description" | Defines which comparator to use when comparing two numeric values
 
| title="Description" | Defines which comparator to use when comparing two numeric values
  
Line 32: Line 33:
 
* [[#Comparator_types|comparator type]]
 
* [[#Comparator_types|comparator type]]
 
|-
 
|-
| title="Attribute" | pattern
+
| title="Attribute" | <code>pattern</code>
 
| title="Description" | Defines regex pattern to be used with [https://en.wikipedia.org/wiki/Regular_expression regex] [[#Comparator_types|comparator type]]
 
| title="Description" | Defines regex pattern to be used with [https://en.wikipedia.org/wiki/Regular_expression regex] [[#Comparator_types|comparator type]]
  
 
Can be
 
Can be
* [[source]]{n}, i.e. <code>[pattern=@string/regex1,@+id/meter_counterDigits,@string/regex2]</code>
+
* <code>[[source]]{n}</code>, i.e. <code>[pattern=@string/regex1,@+id/meter_counterDigits,@string/regex2]</code>
 
|-
 
|-
 
|}
 
|}
Line 44: Line 45:
 
===Compare values===
 
===Compare values===
  
;<code>[name:ComparatorValidator],[message=[[strings.xml|validatorMessage]]],[targetWidget=[[Widget_Library|target]]],[comparator=[[#Comparator_types|comparatorType]],[pattern=[[strings.xml|regexPattern]]]]</code>
+
:;<code>[name:ComparatorValidator],[message=[[strings.xml|validatorMessage]]],[targetWidget=[[Widget_Library|target]]],[comparator=[[#Comparator_types|comparatorType]],[pattern=[[strings.xml|regexPattern]]]]</code>
  
 
====Example====
 
====Example====
<code>@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage</code> - validator message<br>
+
:<code>@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage</code> - validator message<br>
<code>@+id/meter_counterDigits</code> - target to compare<br>
+
:<code>@+id/meter_counterDigits</code> - target to compare<br>
<code>equalLength</code> - comparator type<br><br>
+
:<code>equalLength</code> - comparator type<br>
<code>[name:ComparatorValidator],[message=@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage],[targetWidget=@+id/meter_counterDigits],[comparator=equalLength]</code>
+
:; ⤷ <code>[name:ComparatorValidator],[message=@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage], [targetWidget=@+id/meter_counterDigits], [comparator=equalLength]</code>
  
 
==Comparator types==
 
==Comparator types==
Line 72: Line 73:
 
| title="Description" | Compares is content of validated widget and target is equal
 
| title="Description" | Compares is content of validated widget and target is equal
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
**[[Datatypes#pointer|pointer]] - compares id's of pointers
+
**<code>[[Datatypes#pointer|pointer]]</code> - compares id's of pointers
**[[Datatypes#gps|number]] - compares both longitude and langitude
+
**<code>[[Datatypes#gps|number]]</code> - compares both longitude and langitude
 
|-
 
|-
 
| title="comparatorSign" | <code>!</code> (not equal)
 
| title="comparatorSign" | <code>!</code> (not equal)
 
| title="Description" | Compares is content of validated widget and target is not equal
 
| title="Description" | Compares is content of validated widget and target is not equal
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
**[[Datatypes#pointer|pointer]] - compares id's of pointers
+
**<code>[[Datatypes#pointer|pointer]]</code> - compares id's of pointers
**[[Datatypes#gps|number]] - compares both longitude and langitude
+
**<code>[[Datatypes#gps|number]]</code> - compares both longitude and langitude
 
|-
 
|-
 
| title="comparatorSign" | <code>c=</code> (case ignore equal)
 
| title="comparatorSign" | <code>c=</code> (case ignore equal)
 
| title="Description" | Compares is content of validated widget and target is equal and ignores case
 
| title="Description" | Compares is content of validated widget and target is equal and ignores case
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>c!</code> (case ignore not equal)
 
| title="comparatorSign" | <code>c!</code> (case ignore not equal)
 
| title="Description" | Compares is content of validated widget and target is not equal and ignores case
 
| title="Description" | Compares is content of validated widget and target is not equal and ignores case
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>&amp;gt;</code> (>, greater than)
 
| title="comparatorSign" | <code>&amp;gt;</code> (>, greater than)
 
| title="Description" | Compares if value of validated widget is greater than target value
 
| title="Description" | Compares if value of validated widget is greater than target value
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>&amp;gt;=</code> (>=, greater than or equal)
 
| title="comparatorSign" | <code>&amp;gt;=</code> (>=, greater than or equal)
 
| title="Description" | Compares if value of validated widget is greater than or equal to target value
 
| title="Description" | Compares if value of validated widget is greater than or equal to target value
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>&amp;lt;</code> (<, less than)
 
| title="comparatorSign" | <code>&amp;lt;</code> (<, less than)
 
| title="Description" | Compares if value of validated widget is smaller than target value
 
| title="Description" | Compares if value of validated widget is smaller than target value
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>&amp;lt;=</code> (<=, less than or equal)
 
| title="comparatorSign" | <code>&amp;lt;=</code> (<=, less than or equal)
 
| title="Description" | Compares if value of validated widget is less than or equal to target value
 
| title="Description" | Compares if value of validated widget is less than or equal to target value
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
**[[Datatypes#date|date]]
+
**<code>[[Datatypes#date|date]]</code>
**[[Datatypes#datetime|dateTime]]
+
**<code>[[Datatypes#datetime|dateTime]]</code>
**[[Datatypes#time|time]]
+
**<code>[[Datatypes#time|time]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>regex</code>  
 
| title="comparatorSign" | <code>regex</code>  
 
| title="Description" | Compares if content of regex pattern stored in validator <code>pattern</code> matches the widget content
 
| title="Description" | Compares if content of regex pattern stored in validator <code>pattern</code> matches the widget content
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>true</code> (true)
 
| title="comparatorSign" | <code>true</code> (true)
| title="Description" | Compares if content of validated widget is "true"
+
| title="Description" | Compares if content of validated widget is "<code>true</code>"
 
* valid [[source|sources]] and [[target|targets]]:
 
* valid [[source|sources]] and [[target|targets]]:
**[[Datatypes#status|status]]
+
**<code>[[Datatypes#status|status]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>false</code> (false)
 
| title="comparatorSign" | <code>false</code> (false)
| title="Description" | Compares if content of validated widget is "false"
+
| title="Description" | Compares if content of validated widget is "<code>false</code>"
 
* valid [[source|sources]]:
 
* valid [[source|sources]]:
**[[Datatypes#status|status]]
+
**<code>[[Datatypes#status|status]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>equalLength</code>
 
| title="comparatorSign" | <code>equalLength</code>
| title="Description" | Compares if validated widget GnValue content length is equal to target value  
+
| title="Description" | Compares if validated widget content length is equal to target value  
 
* valid [[source|sources]] and [[target|targets]] which can be combined:
 
* valid [[source|sources]] and [[target|targets]] which can be combined:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
**[[Datatypes#number|number]]
+
**<code>[[Datatypes#number|number]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>equalLengthWidgets</code>
 
| title="comparatorSign" | <code>equalLengthWidgets</code>
 
| title="Description" | Compares if validated widget content length is equal to target value  
 
| title="Description" | Compares if validated widget content length is equal to target value  
 
* valid [[source|sources]] and [[target|targets]] which can be combined:
 
* valid [[source|sources]] and [[target|targets]] which can be combined:
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#text|text]]</code>
**[[Datatypes#text|text]]
+
**<code>[[Datatypes#number|number]]</code>
 
|-
 
|-
 
| title="comparatorSign" | <code>equalLengthWidgetsIgnoreDecimalPart</code>
 
| title="comparatorSign" | <code>equalLengthWidgetsIgnoreDecimalPart</code>
| title="Description" | Is used together with <code>equalLengthWidgets</code>, allowed values <code>true</code> or <code>false</code>. If enabled the <code>equalLengthWidgets</code> will ignore decimal part if a number is entered.
+
| title="Description" | Is used together with <code>equalLengthWidgets</code>, allowed values <code>true</code> or <code>false</code>.
 +
If enabled the <code>equalLengthWidgets</code> will ignore decimal part if a number is entered.
 
|}
 
|}

Revision as of 20:58, 12 July 2017

ComparatorValidator

Description
It performs a comparison of content between two widgets.
IMPORTANT: this validator is not executing required check, if value in widget is null it will return true. You should add RequiredValidator as well to this widget if you need value entered.

Attributes

Note: An attribute marked with asterisk (*) is obligatory
Attribute Description
message* Defines default message to be displayed when validation fails

Can be

  • @string
targetWidget Defines target that will get compared to widget holding the validator.

Validated widget and target have to be of same datatype in order to compare them successfully, with exception of equalLength comparator

comparator Defines which comparator to use when comparing two numeric values

Can be

pattern Defines regex pattern to be used with regex comparator type

Can be

  • source{n}, i.e. [pattern=@string/regex1,@+id/meter_counterDigits,@string/regex2]

Validator signatures

Compare values

[name:ComparatorValidator],[message=validatorMessage],[targetWidget=target],[comparator=comparatorType,[pattern=regexPattern]]

Example

@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage - validator message
@+id/meter_counterDigits - target to compare
equalLength - comparator type
[name:ComparatorValidator],[message=@string/solarMeterEnterValues_currentMeterValueComparatorValidatorMessage], [targetWidget=@+id/meter_counterDigits], [comparator=equalLength]

Comparator types

comparator Description
empty (empty) Compares if value of validated widget is empty
notempty (notempty) Compares if value of validated widget is not empty
= (equals) Compares is content of validated widget and target is equal
! (not equal) Compares is content of validated widget and target is not equal
c= (case ignore equal) Compares is content of validated widget and target is equal and ignores case
c! (case ignore not equal) Compares is content of validated widget and target is not equal and ignores case
&gt; (>, greater than) Compares if value of validated widget is greater than target value
&gt;= (>=, greater than or equal) Compares if value of validated widget is greater than or equal to target value
&lt; (<, less than) Compares if value of validated widget is smaller than target value
&lt;= (<=, less than or equal) Compares if value of validated widget is less than or equal to target value
regex Compares if content of regex pattern stored in validator pattern matches the widget content
true (true) Compares if content of validated widget is "true"
false (false) Compares if content of validated widget is "false"
equalLength Compares if validated widget content length is equal to target value
equalLengthWidgets Compares if validated widget content length is equal to target value
equalLengthWidgetsIgnoreDecimalPart Is used together with equalLengthWidgets, allowed values true or false.

If enabled the equalLengthWidgets will ignore decimal part if a number is entered.