Skip to Content
0

How to valid the form

Oct 23, 2017 at 06:32 AM

40

avatar image
Former Member

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

capture2.png (1.9 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Arjun Biswas Oct 23, 2017 at 08:59 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Daniel Degraf
Oct 23, 2017 at 07:01 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 23, 2017 at 07:31 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Irfan Gokak Oct 23, 2017 at 08:05 AM
0

Hi Riya,

Do you want validate on submit?

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Irfan,

No, I don't want validate on submit

0