Additional ways of letting SAPUI5 generate messages?

Viewed 41

One way of creating validation error messages, in this case from Input's minLength & maxLength ...

<Input
  placeholder="Enter name"
  valueStateText="Error Text."
  value="{
    path: '/firstName',
    type: 'sap.ui.model.type.String',
    constraints: {
      minLength: 1,
      maxLength: 10
    }
  }"
/>

..., is to register the control or view beforehand via MessageManager:

sap.ui.getCore().getMessageManager().registerObject(oView, true);

Is there a way of automatically generating constraint specific messages without using MessageManager?

If there isn't a way, how is it usually done? Are all views registered in the Component.js or each view's onInit has a MessageManager section as mentioned above?

1 Answers

You can also enable the automatic message generation in the application descriptor (manifest.json) section /sap.ui5/handleValidation as mentioned in the documentation topic Validation Messages.

{
  "sap.ui5": {
    "handleValidation": true
  }
}

handleValidation

Possible values: true or false (default); used to enable or disable validation handling by the message manager for this component, see Error, Warning, and Info Messages.

Source: Descriptor for Applications, Components, and Libraries (manifest.json)

Demo: https://embed.plnkr.co/L0ADaEBKvexsrrKk

Related