on 10-23-2017 7:32 AM
Hi,
I want to validate the form when i am pass the blank in the field it will show me required
In attachments there is two field when i am pass the blank in tech id.So, it will show me mandatory.capture2.png
You can use the value state property of sap.m.Input for this purpose.
Code for your input field :
<Input id="uid" placeholder="{i18n>User_ID}" width="20rem" liveChange="handleLiveChange" required="true"></Input>
<Input id="pasw" placeholder="{i18n>Password}" type="Password" width="20rem" liveChange="handleLiveChange" ></Input>
Code for your controller handleLiveChange function
/**
* To validate the input fields.
* @public
*/
handleLiveChange: function(oControlEvent){
if(oControlEvent.getParameters().value.length == 0){
oControlEvent.getSource().setValueState(sap.ui.core.ValueState.Error);
}
else{
oControlEvent.getSource().setValueState(sap.ui.core.ValueState.None);
}
},
Hope this helps,
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Riya,
Do you want validate on submit?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel thanks for sharing the code but it's not working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The easiest way is to use the attribute liveUpate of each of your input fields.
View:
<Input ... valueLiveUpdate="true" liveChange="myFunction" ... />
Controller:
myFunction: function(oEvent) {
var value = oEvent.getParameter('value');
if (value === '') { oEvent.getSource().setValueState("Error"); }
}
Keep in mind that this event only will be thrown, if the Input field is changed. If the user directly clicks "Save" or so, you'll have to make sure the validation is executed before saving. One possible (better) implementation is explained here: https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.InputChecked/preview
(Click the Button on the very top right to see the code)
Cheers
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.