cancel
Showing results for 
Search instead for 
Did you mean: 

Initializing view data....

former_member239819
Participant
0 Kudos

Where, and how do I clear out the input date on a view....

E.g. when the data is saved, and I access my page from the menu, the old data is still displayed in the input boxes.

I've tried the onInit() function but that only fires the first time into the view.

Accepted Solutions (1)

Accepted Solutions (1)

jamie_cawley
Advisor
Advisor
0 Kudos

You could clear it on a successful save or you could use a routematched event of a router.

Regards,

Jamie

SAP - Technology RIG

former_member239819
Participant
0 Kudos

I'm clearing the fields on routematched which work ok....

However, I don't want it to clear when I navback, but this still call _onroutematched() .

Is there a way to clear EXCEPT when I NavBack?

jamie_cawley
Advisor
Advisor
0 Kudos

Are you checking the route name?

oEvent.getParameter("name")

Regards,

Jamie

SAP - Technology RIG

venkatachala_ck
Active Participant
0 Kudos

Hi Adam,

instead writng your clear code in route match

write it after navTo function()

this.getRouter().navTo("itemDetail");

(or)

you can put your data into json model and bind it again.

on navback

Regards,

Venkat

former_member239819
Participant
0 Kudos

The navto call is in the BaseController which calls the defaultTimes page (view/controller).

onNavToDefaultTimes : function(oEvent) {

  this.getRouter().navTo("defaultTimes");

  }

My clear code was in the _onRouteMatched function of detaultTimes.....

_onRouteMatched : function(oEvent) {

  var view = this.getView();

  view.byId("shopInput").setValue("");

  view.byId("effectiveDateFrom").setValue("");

  view.byId("shop24Hrs").setSelected(false);

  view.byId("shopClosed").setSelected(false);  

  },

The problem is though, _onRouteMatched is also callled from navBack of the page following default times. And I don't want to clear the fields in this case.

How do I implement the clear from the onNavToDefaultTimes function of the base Controller only?

Can you give an example.

former_member239819
Participant
0 Kudos

You it always gets the route name. But as you can see below, the problem is clearing from onRouteMatched() 

(I don't want to clear on NavBack.

jamie_cawley
Advisor
Advisor
0 Kudos

I would do something like

_onRouteMatched : function(oEvent) {

     if(oEvent.getParameter("name") != 'defaultTimes'){

          return;

     }

  var view = this.getView();

  view.byId("shopInput").setValue("");

  view.byId("effectiveDateFrom").setValue("");

  view.byId("shop24Hrs").setSelected(false);

  view.byId("shopClosed").setSelected(false); 

  },

Regards,

Jamie

SAP - Technology RIG

former_member239819
Participant
0 Kudos

The problem is, on navBack, the name is still 'defaultTimes' and the data is cleared even if I don't want it to be

It's only a small issue, I'll just clear the data every time (even on navBack).

Thanks for you help.

venkatachala_ck
Active Participant
0 Kudos

try Jamie Cawley code (or) try this

onNavToDefaultTimes : function(oEvent) {

  this.getRouter().navTo("defaultTimes");

var view = this.getView(); // use instance defaultTimes instead of this.getView();

  view.byId("shopInput").setValue("");

  view.byId("effectiveDateFrom").setValue("");

  view.byId("shop24Hrs").setSelected(false);

  view.byId("shopClosed").setSelected(false);  

  }

Regards,

Venkat

jamie_cawley
Advisor
Advisor
0 Kudos

How are you navigating back?

Regards,

Jamie

SAP - Technology RIG

former_member239819
Participant
0 Kudos

That doesn't work, as this.getView() is undefined.  (Because I'm not in the defaultTimes view yet.

No problem though, I'll leave it to always clear...

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

when you leave the view or enter the view again. bind the model to the ui elment, clear the model data

former_member239819
Participant
0 Kudos

Can you give an example?

junwu
Active Contributor
0 Kudos

no