Skip to Content

How Can I delete an input field after I leave the View?

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:

Here's my code:


<layout:PositionContainer left="136px" top="244.01171875px">
	id ="HeadInput"
	width = "743px"
	placeholder="Ingresa Encabezado..."
	valueStateText="El encabezado no debe estar vacío"
        value= "{path: '/head',
	type: 'sap.ui.model.type.String',
	minLength: 1,
	maxLength: 40
<layout:PositionContainer left="136px" top="301.01171875px">
	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


 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 = [
			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 {
				} catch (oException) {
					bValidationError = true;

			// output result
			if (!bValidationError) {"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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 13, 2018 at 07:45 AM

    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 :""}));
    Add comment
    10|10000 characters needed characters exceeded

    • Jun Wu Juan Arturo Diaz Aguilar

      like I said before, you just want to clean your plate(model), no need to go to market buy a new plate(new model) to have the clean plate and throw the old one.

  • Apr 12, 2018 at 07:24 PM

    get your model and set the property(which bound to the input) value to ""




    Add comment
    10|10000 characters needed characters exceeded