sv1jsb
sv1jsb

Reputation: 70

jquery mobile refire pagebeforecreate event

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

Upvotes: 1

Views: 1432

Answers (2)

sv1jsb
sv1jsb

Reputation: 70

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.

Upvotes: 1

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262939

You can use trigger():

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

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

$("#mypage").data("page")._trigger("beforecreate");

Upvotes: 0

Related Questions