2

I have a small jQuery mobile app I'm writing, one of the pages has a form. The form is retaining field values and dom manipulations when I navigate away from it. I want to stop this, basically start the form and the dom from fresh on pageShow.

I could just manually clear the fields and remove any classes I've injected into the dom but surely there most be a better way to do this?

thanks in advance

Jimothey
  • 2,414
  • 9
  • 41
  • 66
  • redirect to itself on document ready for once :) – Pabuc Nov 12 '12 at 15:04
  • Wouldn't that add a refresh though? I'm wanting to avoid any refreshes. – Jimothey Nov 12 '12 at 15:06
  • I could just do $(this).closest('form').find("input[type=text], textarea").val(""); but I thought there might be a cleaner jquery mobile way to do it? – Jimothey Nov 12 '12 at 15:07
  • Could you put `autocomplete="off"` on the form? https://developer.mozilla.org/en-US/docs/HTML/Element/Input, but you may want to make sure it offers the proper compatibility you're looking for: http://stackoverflow.com/questions/3868299/is-autocomplete-off-compatible-with-all-modern-browsers – Chase Nov 12 '12 at 15:07
  • If you have the form template or code in a separate place you could just as well replace the html on page load: `$('form').html($('#selector-of-your-template').html())` – Tallmaris Nov 12 '12 at 15:32

1 Answers1

2

You are likely using ajax based navigation which simply loads new pages into the existing DOM. Add data-ajax="false" to your links.

It is important to understand that there are pros and cons to either of these approaches. Ajax loading is targeted at addressing improved performance when navigating between pages.

You can also add this same attribute and value to the form tag to keep jQuery Mobile from using ajax on form submissions.

andleer
  • 22,388
  • 8
  • 62
  • 82