From wiki.ginstr.com
Jump to: navigation, search

gn:act_validators

Description
Action used to enable or disable xml defined validators on widgets. As long as the screen is not destroyed and kept in memory the validator states will be kept. Once screen is parsed again the validation rules will default to definitions in xml.
Action returns
void

Action signatures

[gn:act_validators]|[action;validatorTypes{n};ids{n};targets{n}]
Parameter Description
action Action which will be taken on targeted validators.
  • Can be:
    • enable - enables validator
    • disable - disables validator
ids{n} (optional) Specific ids to target on certain widget or widgets if there are multiple defined. If defined then validatorTypes can not be used. Can be used to target specific validator. It is possible with ids to group certain validators by id. In that case if you make changes on a group all validators which share the id will be affected by action.
  • Can be validator id, hardcoded:
    • any widget validator id that is defined on the screen in xml
validatorTypes{n} (optional) Specific validators to target on certain widget or widgets if there are multiple defined. If defined then ids can not be used.
targets{n} (optional) target target or targets to which action will be applied. If no targets are defined all widgets on screen that have validators will be targeted.
  • Valid target:
    • any widget that has validator in xml defined

Example

initial state

validators on widgets "@+id/bebraObjekte_ObjektNummer" and "@+id/bebraObjekte_ObjektVerwalter" will be loaded on screen load.

screen.xml
<FrameLayout
    android:id="@+id/exampleFrame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    gn:act_set="[gn:act_validators]|[disable;;@+id/bebraObjekte_ObjektVerwalter],
    [gn:act_validators]|[disable;;a;@+id/bebraObjekte_ObjektNummer],
    [gn:act_validators]|[enable;ComparatorValidator;;@+id/bebraObjekte_ObjektNummer]" />

<com.ginstr.widgets.GnEditText
    android:id="@+id/bebraObjekte_ObjektNummer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    gn:act_validate="[name:RequiredValidator],[message=@string/addObject_numberRequiredValidatorMessage]"
    gn:act_validate2="[name:ComparatorValidator],[message=@string/validators_editNumberComparatorValidatorMessage1],[comparator=&gt;],[targetWidget=@variable/numberZero],[id=a]"
    gn:act_validate3="[name:ComparatorValidator],[message=@string/validators_editNumberComparatorValidatorMessage2],[comparator=&lt;],[targetWidget=@variable/numberTen],[id=b]"/>

<com.ginstr.widgets.GnEditText
    android:id="@+id/bebraObjekte_ObjektVerwalter"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    gn:act_validate="[name:RequiredValidator],[message=@string/addObject_managerRequiredValidatorMessage]"/>		
after action execution

Once FrameLayout "@+id/exampleFrame" "gn:act_set" is exectued all validator on widgets "@+id/bebraObjekte_ObjektVerwalter" will be disabled, and "@+id/bebraObjekte_ObjektNummer" validator with id "a" will be disabled and after that both "ComparatorValidator" validators will be enabled