I have a sap.m.Input with a regex binding. When my input is "A", "B" or "C" my text is black, otherwise it becomes red through CSS.
oComponent.attachValidationError(function(oEvent) {
oEvent.getParameter("element").addStyleClass("become-red");
});
oComponent.attachValidationSuccess(function(oEvent) {
oEvent.getParameter("element").removeStyleClass("become-red");
});
var oInput = new sap.m.Input( {
value: {
path: "Qux>/foo/0/bar/0/baz",
type: new sap.ui.model.type.String(null, {
search: new RegExp("^[ABC]$")
})
}
});
When the value is "A" and I change it to "B", this works properly.
Then, if I do
oModelQux.setProperty("/foo/0/bar", [{
"baz" : "A"}]);
This works properly, the value becomes "A" again. My problem is that when I change the value of the input to a value which is not alllowed (e.g. "D"), and then I try my code
oModelQux.setProperty("/foo/0/bar", [{
"baz" : "A"}]);
nothing happens. The input does automatically update to "A", it just leaves the string "D" in red.
The binding should avoid that wrong values are stored in the model. If you change the value from "A" to "D" the value is never stored in the model, i.e. the model holds still "A". Thus your call to setProperty has no effect, as the internal value of the binding has never changed and setProperty does not force bindings to update in case of unchanged data. I suggest that you obtain the binding of the input field if the button is clicked and call refresh(true). This should work (not tested).
Beside that I would suggest to use a Select control as it looks like that the available values are fixed. This would make the special logic obsolete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With