Skip to Content
avatar image
Former Member

How to validate only mandatory fields in a form in SAP UI5?

I need to validate just the mandatory fields in a form. There are multiple controls like select, input of type(text, number), combo box .. etc.
Could anyone please help?

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 10 at 01:28 PM

    Hi Shreya,

    Check this sample that illustrates how to use the constraints on a particular display controller that has been registered with the Message Manager. Once this is done, the framework will deal with the displaying of specific messages related to each field that failed validation.

    Using constraints is simple as it takes the field's model type into account. So if you declare it as being an Integer, then the framework will take care to accept only numbers without decimal separators, etc. The validation messages are also embedded into the framework - so they are already internationalized.

    If you need any custom validation or custom display messages, you may extend the SimpleType type with your own validation rules and messages. Check the example on the sample as it contains both use cases.

    Regards,
    Ivan

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Shreya,

      What you have just described is the "old" style of html field validation. SAPUI5 faces this differently so you don't need to do any additional checks based on field's attributes. Just by making the field mandatory it already triggers a validation. There are two basic triggers that will run validation for fields - screen updates (any data change on the model) or when the field changes focus (onEnter or onFocus). Since all the possible triggers are already covered you don't need to implement your own triggers. SAPUI5 is smart enough to do all validations at once. This a better approach, since it doesn't "lock" the user on a particular field and allows one to enter data and worry about validations latter. This way the UX gets better, even for users that are not so confident about what your application is expecting.

      Regards,
      Ivan