I was looking for a solution to validate my email TextInput field and some guys at #slack helped me, so I’m just sharing with the community how I solved this problem.
To whom are interested in, here is my code to validate a <TextInput>
email field:
<TextInput ux:Class="EmailInput" Value="{Property Text}" InputHint="{Property HintType}" PlaceholderText="e-mail" Margin="15" TextColor="{Property ValidationColor}" ValidationColor="#000" PlaceholderColor="#44444450">
<string ux:Property="Text" />
<Fuse.Controls.TextInputHint ux:Property="HintType" />
<bool ux:Property="IsValid" />
<float4 ux:Property="ValidationColor" />
<WhileNotFocused>
<JavaScript>
// Simple validation just for this example
console.log( "Text: " + this.Text.value );
this.IsValid.value = false;
var text = this.Text.value;
if(text && text.length > 3 && text.indexOf('@') != -1 && text.indexOf('.') != -1) {
this.IsValid.value = true;
} else {
this.IsValid.value = false;
}
</JavaScript>
<WhileFalse Value="{Property IsValid}">
<Change this.ValidationColor="#ff3300"/>
</WhileFalse>
<WhileTrue Value="{Property IsValid}">
<Change this.ValidationColor="#000"/>
</WhileTrue>
</WhileNotFocused>
</TextInput>