cancel
Showing results for 
Search instead for 
Did you mean: 

How to valid the form

10-23-2017 8:32 AM
riyatickoo Explorer
1042 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

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.

Answers (3)

Answers (3)

irfan_gokak
Contributor
0 Likes

Hi Riya,

Do you want validate on submit?

riyatickoo
Explorer
0 Likes

Hi Irfan,

No, I don't want validate on submit

riyatickoo
Explorer
0 Likes

Hi Daniel thanks for sharing the code but it's not working

Former Member
0 Likes

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