Skip to Content

How to valid the form

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 23, 2017 at 08:59 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2017 at 07:01 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2017 at 07:31 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2017 at 08:05 AM

    Hi Riya,

    Do you want validate on submit?

    Add comment
    10|10000 characters needed characters exceeded