[SOLVED]How to send data to previous page when clicking back button

How could I send data to previous page when clicking back button like smart select?

Could anyone pls tell me how can do? Callback function or ?

Thanks.

maybe with the use of the router event “routeChange” ?
or programmatically, using the options of router.back… I’m interested by the answer too !

Hi @Francois-Xavier_G,
Thanks for your reply. Actually, I would just like to get a value I chose in a new page and pass it to the previouse page when clicking the back button.

I have seen the source code of smart select, I got the method is ‘ss.$valueEl.text(valueArray.join(’, ‘));’ and I have tried to use the same method in my application, although I can get the object and set the new value to this object in new page, the value I set in new page didnt change when back to the previous page.

why don’t you save it to app.data when you choose the value, and get it back in the previous page ?

I will save all of value on the previous page and then I have to reload these value? Do you know I mean?

I just want to know is there a method like smart select that only one value can be modified?

Thanks again for your reply.

the app variable is reachable anywhere, so you can save in app.data what you want for next use (more or less like window object in vanilla js).

If you are in page P2, with a html element that collects a value, you can :

  • collect the value with a listener
  • store it to app data
  • go to previous page (page P1)
  • recall the value with app.data.myvalue.

so you don’t need to “send data to previous page when clicking back button” because you have saved it before.

Smart select is just a select, so you can target it by dom and put listeners to it.

$$('select[name="fruits"]').on('change click', function(ev){
   // save your data, 
   // app.data.mySelectedValue  = $$('ev.currentTarget).val();
})

Hi @Francois-Xavier_G,

Thanks for your reply and help. You are right, I don’t need to send data!!!

I got it.

Thank you.

It will depend on your app, but as a basis, i prefer to store all information given by users for later purpose. If there is a database, i’ll send it when it arises, else i will save it to app storage to prevent assigning over and over data from one page to the others. It’s an habit inherited with the DRY principle (Don’t repeat yourself).

You can save data into the route also, i have many methods in my routes, and / or data, that i can call with app.(route.)route.methods.mymethod(); easier to read / maintain, and callable several times.