Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

leftover "removed" fields make trouble for client-side validation #50

Closed
eostrom opened this issue May 30, 2011 · 4 comments
Closed

leftover "removed" fields make trouble for client-side validation #50

eostrom opened this issue May 30, 2011 · 4 comments
Labels

Comments

@eostrom
Copy link

eostrom commented May 30, 2011

If you add an item, get its inputs into an invalid state (e.g., by leaving a required field blank), and then remove the item, client_side_validations (and probably other client-side validation solutions) will still flag the now-hidden fields as invalid, but the user has no way to "correct" them.

I can work around this from the validation side, but I'm thinking, is there any reason to keep the .fields around once an element is removed? What if we just remove it, or replace it with the hidden 'destroy' input if there is one?

@hzamani
Copy link

hzamani commented Jun 8, 2011

if we remove .fields the _destroy input will be removed and no destruction will happen.
I don't know replacing with _destroy is good or not, but simply setting the hidden filed values to empty may work,
just after $(this).closest('.fields').hide(); add this:
$(this).closest('.fields').find(":input:hidden").each(function() { $(this).val(""); });

@eostrom
Copy link
Author

eostrom commented Jun 8, 2011

It seems like that has the reverse of the desired effect: It nullifies the _destroy input (so the item won't be deleted), but leaves the other fields intact (so client_side_validations will flag invalid input, even though it's supposed to be deleted).

@hzamani
Copy link

hzamani commented Jun 8, 2011

I made a mistake here, and you are right. I don't think there is a reason by not to remove that elements, because there is no way to access fields after hiding them (at least for now). And for this problem it's enough (and also more easy) to only remove the inputs from form and hide the rest, by putting:

`````` $(this).closest('.fields').find(":input:visible").remove();before$(this).closest('.fields').hide();```.

@lest
Copy link
Collaborator

lest commented Sep 17, 2012

You could use javascript events to perform any custom actions when fields are either added or removed.

@lest lest closed this as completed Sep 17, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants