1

I have a form which is posted to the same url and the reponse is the form fields again with some new data derived from the form.

At my page I have:

$(document).delegate("#mypage","pagebeforecreate", function(){
     //some stuff
});

This is fired when the page is first accessed but not when the form returns from post.

Is there a way to refire the pagebeforecreate event?

Thank you for any input. Andreas

sv1jsb
  • 70
  • 9
  • Is the new data actually being inserted into the DOM, or is it just reusing the old page? And can you post the `
    ` tag attributes you are using?
    – PinnyM Oct 17 '12 at 21:17
  • The new page is inserted correctly. No problem there. The problem is: when or better yet, where to bind a function to manipulate the NEW data AFTER the form has returned the new data. The only thing I succeeded is bind with setTimout. `$(document).delegate("#mypageid","pageinit", function() {setTimout(function(){$("#collapsible").trigger("collapse")}, 2000)});` It works fine, but it's not very pretty. I think the problem is that the pageinit event is firing to early, before all widgets are initialized. – sv1jsb Oct 18 '12 at 13:09

2 Answers2

1

After a lot of digging the correct way to do that is use document and not page-id like so:

$(document).on("pageinit","selector",function(){
    // your code here
});

This will ensure that you catch the pageinit when the "page-id" is inserted to the DOM.

sv1jsb
  • 70
  • 9
0

You can use trigger():

$("#mypage").trigger("pagebeforecreate");

Alternatively, you could call the internal _trigger() method of the page widget:

$("#mypage").data("page")._trigger("beforecreate");
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • When should I call the trigger? The problem is that no events are firing when you load the page the second time. – sv1jsb Oct 17 '12 at 20:25
  • @sv1jsb, ah, sorry, from your question I thought you already solved this. Did you try calling it from a `pageload` handler (only bound for the duration of the submission)? – Frédéric Hamidi Oct 17 '12 at 20:40
  • The problem I think is that because the form is posted to the same url, the return data take the place of the old. I tried all known events: pagecreate, pageinit, pageload, pageshow and all the "before"s. No one seems to be fired when returning from post. – sv1jsb Oct 17 '12 at 21:05