Jump to content

jQuery Not


Pete
 Share

Recommended Posts

Hi guys

For various complicated reasons I have fields re-used in a form with text around them, and various conditions show one set of text with the fields inline and hide the others. As such, it's a mess when I submit :)

What I need to do is, on submit, remove all hidden fields (hidden by their parent containers not being visible, not fields with type=hidden) and exclude asmSelects from being removed since the field the ASMSelect data is stored in is always hidden.

I had come up with something like this:

$("#myform *:hidden").not("[type=hidden], name*='[]").remove();

But it's not idiot-proof really as 1) it doesn't work and 2) even if it did, I'm detecting ASMSelect's by searching for [] in the field name. These latter fields could be in a hidden section and should therefore be skipped.

What I really need is to iterate all fields, remove all where the PARENT element is hidden and never remove input type=hidden and I think that would work, however my brain certainly doesn't work right now :)

Any ideas? I know it's going to be a simple one-liner that I kick myself over.

Link to comment
Share on other sites

I guess what I need is something like this (which is untested as I need to leave the house now and probably doesn't work):

Basically for each hidden input, if the parent is hidden then remove it. That should capture everything I need it to then.

$("#myform *:hidden").parent(":hidden").remove();

All suggestions are very welcome.

Link to comment
Share on other sites

I guess what I need is something like this (which is untested as I need to leave the house now and probably doesn't work):

Basically for each hidden input, if the parent is hidden then remove it. That should capture everything I need it to then.

$("#myform *:hidden").parent(":hidden").remove();

All suggestions are very welcome.

That should work fine. But I don't know what the markup is so there could be side effects for other hidden elements?

Link to comment
Share on other sites

What I need to do is, on submit, remove all hidden fields (hidden by their parent containers not being visible, not fields with type=hidden) and exclude asmSelects from being removed since the field the ASMSelect data is stored in is always hidden.

If you gave all those containers (except the one with the ASMSelect data) a certain classname, you could use a jquery selector targeting hidden containers with that classname to remove the containers (and their contents).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...