on 04-12-2018 6:39 PM
Hi experts...
I have 2 input fields in my sapui5 app, and I want to validate them.
I succesfully did it, but now the text that I write inside the input fields remains even when Im get out of my view...
How can I do it to delete the data from the input fields before I leave the xml view?
I have my codereference from here:
https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.InputChecked/code
Here's my code:
XMLVIEW.
<layout:PositionContainer left="136px" top="244.01171875px">
<layout:control>
<Input
id ="HeadInput"
width = "743px"
placeholder="Ingresa Encabezado..."
valueStateText="El encabezado no debe estar vacío"
value= "{path: '/head',
type: 'sap.ui.model.type.String',
constraints:
{
minLength: 1,
maxLength: 40
}
}"
valueLiveUpdate="true"
/>
</layout:control>
</layout:PositionContainer>
<layout:PositionContainer left="136px" top="301.01171875px">
<layout:control>
<Input
id ="SubHeadInput"
width = "743px"
placeholder="Ingresa Sub Encabezado..."
valueStateText="El subencabezado no debe estar vacío"
value= "{path: '/subhead',
type: 'sap.ui.model.type.String',
constraints : { minLength: 1,
maxLength: 40
}
}"
valueLiveUpdate="true"/>
</layout:control>
</layout:PositionContainer>
JSVIEW:
onInit : function () {
var oView = this.getView();
oView.setModel(new JSONModel({
head : "",
subhead : ""
}));
// attach handlers for validation errors
sap.ui.getCore().getMessageManager().registerObject(oView.byId("HeadInput"), true);
sap.ui.getCore().getMessageManager().registerObject(oView.byId("SubHeadInput"), true);
},
onContinue : function () {
// collect input controls
var oView = this.getView();
var aInputs = [
oView.byId("HeadInput"),
oView.byId("SubHeadInput")
];
var bValidationError = false;
// check that inputs are not empty
// this does not happen during data binding as this is only triggered by changes
jQuery.each(aInputs, function (i, oInput) {
var oBinding = oInput.getBinding("value");
try {
oBinding.getType().validateValue(oInput.getValue());
} catch (oException) {
oInput.setValueState("Error");
bValidationError = true;
}
});
// output result
if (!bValidationError) {
MessageToast.show("Todos los campos validados, el aviso se creo correctamente");
var oHistory, sPreviousHash;
oHistory =new sap.ui.core.routing.History.getInstance();
sPreviousHash = oHistory.getPreviousHash();
if (sPreviousHash !== undefined) {window.history.go(-1);}
else { this.getRouter().navTo("tileadmin", {}, true /*no history*/);}
} else {
MessageBox.alert("Complete todos los campos para poder continuar");
}
}
Best Regards.
Call this code, on success. This will reset the data to empty values once again. The idea is to clear the values set to the model(bound to the view).
oView.setModel(new JSONModel({head:"",
subhead :""}));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
get your model and set the property(which bound to the input) value to ""
oView.getModel().setData({})
or
oView.getModel().setProperty("/head","");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.