1

So I'm dynamically inserting text inputs into a jQuery mobile page that is inside an iframe. I can get it to insert correctly but the trigger('create') method doesn't apply any jqm styles, although it doesn't throw any javascript errors either.

Code on the page that inserts into iframe:

 $('.textarea').click(function() {
   $('#form').contents().find('#maincontent').append('<div data-role="fieldcontain"><label for="insert">Text Input:</label><input type="text" name="insert" id="insert" value="" /></div>');
   $('#form').contents().find('#maincontent').trigger('create');
});

And here is the boilerplate jqm maincontent (I've excluded header/footer for easier reading) that is inside the iframe (prior to inserting new text input)

<div data-role="content" id="maincontent"> 
 <div data-role="fieldcontain">
     <label for="name">Text Input:</label>
     <input type="text" name="name" id="name" value=""  />
 </div>
</div>
2
  • I don't see any code for the "create" event. Did you mean the "pagecreate" event? Commented Aug 31, 2011 at 20:11
  • It is a built in jqm function (at least to my knowledge) see the comment I left below to eltuza's answer for more info Commented Aug 31, 2011 at 22:31

4 Answers 4

0

I make the following assumptions:

  • #form is the ID of your iframe.
  • The content from the iframe comes from the same domain.

Have you tried this:

$('.textarea').click(function() {    
  var iframecontent = $('#form').contents().find('#maincontent');
  var newstuff = $('<div data-role="fieldcontain"><label for="insert">Text Input:</label><input type="text" name="insert" id="insert" value="" /></div>');
  newstuff.appendTo(iframecontent).trigger('refresh');
});
Sign up to request clarification or add additional context in comments.

2 Comments

Nope didn't work. I also tried doing both a create and a refresh and that didn't work either.
Also your assumptions are correct. Thanks for taking the time to give it a shot :)
0

the create event might be firing, but where are you listening to it and responding?

for that means, you might need something like

$("#maincontent").bind('create', function() {
    //respond to the fired event
})

1 Comment

Reading the jquery mobile release for beta 2 (jquerymobile.com/blog/2011/08/03/jquery-mobile-beta-2-released) there is a built in create method. Search "New "create" event" to find it in the announcement
0

Run this line after you make all your insertions.

$('body').append(html).trigger('create');

Trick found by another SO user https://stackoverflow.com/users/456850/devin-dixon (Original Question).

Comments

0

Create a function inside iframe and include trigger('create') method in that function. Then call to that function outside from the iframe.

see this .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.