contributte / live-form-validation

:no_entry: Nice client-side live form validation for Nette Forms.
https://contributte.org/packages/contributte/live-form-validation.html
BSD 3-Clause "New" or "Revised" License
59 stars 24 forks source link

RadioList, CheckboxList: validation error is removed only on selecting first item #15

Closed rolandtoth closed 8 years ago

rolandtoth commented 8 years ago

When using RadioList or CheckboxList, the validation error goes away only if I select the first input. Also, the error spans doesn't populate, except the first one (but maybe this is intentional).

I'm using the default renderer:

$choices = array(
    'a'    => 'aaa',
    'b'   => 'bbb',
    'c'         => 'ccc'
);
$form->addCheckboxList('my_choices', 'Please select'), $choices)
    ->setRequired('Required field');

Am I doing something wrong?

Robyer commented 8 years ago

Sorry, I don't have time to deal with this, so if you can make it work and provide pull request, that would be great.

Maybe it's because internally I'm using old netteForms.js (I haven't checked lately if there were any changes) or it just needs special handling of these *List elements.

rolandtoth commented 8 years ago

Ok, I will get into this when I'll have some time.

If I replace the NetteForms.js part in the code, the problem still exists. Maybe it's in the original code? I have no Nette projects where I can try this (using Nette Forms as standalone).

rolandtoth commented 8 years ago

Here is a quick fix but I'm not sure how general is it: https://github.com/Robyer/nette-live-form-validation/compare/master...rolandtoth:patch-1

This finds the first error message tag and empties that.

I don't understand why are there several error messages on RadioList/CheckboxList controls and not just only one. Is this by design? Can a radio or a checkbox item validated individually in RadioList/CheckboxList controls?

Robyer commented 8 years ago

I don't understand why are there several error messages on RadioList/CheckboxList controls and not just only one.

Because LiveFormValidation wasn't prepared for that (when original author created it, such elements wasn't supported in Nette).

I pushed correct fix, along with updated internal netteForms.js.

Try version 1.7.0 :)

rolandtoth commented 8 years ago

Thanks, seems to work fine at first sight.

Btw, the error message IDs for multi elements start with "-" (eg. "-areas_message"). Is this intentional? Looks weird but according to the specs it should be valid in HTML5.

Robyer commented 8 years ago

Btw, the error message IDs for multi elements start with "-" (eg. "-areas_message").

Does your form has ID? I'm creating new id as formId + "-" + elemName.

rolandtoth commented 8 years ago

No, there's no form ID.

Robyer commented 8 years ago

So that's the reason. But Nette by default gives every form an ID, you have it intentionally without it?

rolandtoth commented 8 years ago

I guess that's because I use Nette Forms standalone. I see there's a "frm-..." ID when using the framework. Maybe you could add "frm" prefix if there's no ID?

Robyer commented 8 years ago

What ID do you see for your inputs (e.g. if you have name="areas")? I can use "frm" or no prefix at all. I'm not sure what's better.

rolandtoth commented 8 years ago

Here you can view the form: http://mosolygo.paqartdesign.com/en/contacts/be-our-volunteer/

Robyer commented 8 years ago

Aha, I think it would be better (and safer) to use ID for your forms. Maybe it will also automatically prefix all your input ids (as FW does it)?

Anyway, I'll keep it without "frm" prefix for now.

rolandtoth commented 8 years ago

All right, thanks for your inputs :) No, there's no auto prefixing when there's an ID but that no problem.