docs

Validation Messages

Validation messages are either created by the framework and processed by thesap.ui.core.message.ControlMessageProcessor or manually by the application.


Target

The target of a validation message can be empty. In this case, the message has no specific target and is relevant for the whole application. If a target is set, the target is a string consisting of a control ID, a slash (”/”), and the name of the property to which the message applies.

Example: label0/text


Lifecycle

Validation messages are added with a target referencing a control and its specific property. The messages are kept until a validation message for the property is created and assigned. If new data for the same property is received from the server, the validation messages are erased unless their persistent property is set to true.


Automatically Created Messages

Validation messages are generated by the framework type validation when data changes. If a bound property has an assigned type, the validation can trigger the message creation. To activate the automatic message creation, the following options exist:


Manually Created Messages

You can also create validation messages manually and add them to the sap/ui/core/Messaging module. If you add the message to a control property that is bound and validated by a data binding type, your message gets deleted when new validation results from the type comes in. You can override this behavior by setting the persistent property of the message to true.

// "ControlMessageProcessor" required from module "sap/ui/core/message/ControlMessageProcessor"
// "Messaging" required from module "sap/ui/core/Messaging"
// "Input" required from module "sap/m/Input"
// "Float" required from module "sap/ui/model/type/Float"
// "Message" required from modle "sap/ui/core/message/Message"
var oMessageProcessor = new ControlMessageProcessor();

Messaging.registerMessageProcessor(oMessageProcessor);

var oInput = new Input({
    id: "myInputId",
    value: { path: "/Products(1)/Price" , type: Float }
});

Messaging.addMessages(
    new Message({
        message: "ZIP codes must have at least 23 digits",
        type: sap.ui.core.MessageType.Error,
        target: "myInputId/value",
        processor: oMessageProcessor
     })
);

Related Information

API Reference: sap.ui.core.ControlMessageProcessor

API Reference: module:sap/ui/core/Messaging