Validating form is more over important in UI development. Here is the simple example for validating a number field in lightning component app.
Please take a look on the below link, if you don't know about creating lighting component.
Lightning Component Code:
- <aura:component >
- <center>
- <br/>
- <h5> <b> Age Validator </b> </h5> <br/>
- Enter your age: <ui:inputNumber aura:id="inputCmp"/> <br/>
- <ui:button label="Submit" press="{!c.validateAge}"/>
- </center>
- </aura:component>
Component Controller Code:
- {
- validateAge : function(component) {
- var ageField = component.find("inputCmp");
- var ageValue = ageField.get("v.value");
- if(isNaN(ageValue) || ageValue == '')
- {
- ageField.set("v.errors", [{message:"Enter a valid age."}]);
- }
- else if(parseInt(ageValue) > 150)
- {
- ageField.set("v.errors", [{message:"This is not a valid age."}]);
- }
- else if(parseInt(ageValue) < 18)
- {
- ageField.set("v.errors", [{message:"Minimum age to submit this form should be greater or equal 18"}]);
- }
- else
- {
- ageField.set("v.errors", null);
- }
- }
- }
can we Increase that error message size?..if its how can we do that??
ReplyDelete