Karevan
Karevan

Reputation: 139

How to use jQuery.validity properly

Yesterday, I started here asking a question about my own project, and when I saw how helpful the people are and how fast they answered, I was really happy. My father is making a project by himself, and he asked me to write a question here for him because of English knowledge matters.

Well, he is trying to validate a form using jQuery.validity ( http://validity.thatscaptaintoyou.com ), but his function of validation is not working. Here is his code: http://pastebin.com/uvXRTZsE

I'm sorry for not pasting it here, but after several tries, parts of the code were missing when pasting them here.

Upvotes: 2

Views: 1295

Answers (2)

Darwin
Darwin

Reputation: 87

Validity doesn't have any documentation supporting radio button validation but you can do:

$('#form').validity(function(){
    $('#my_input_radio').assert($('#my_input_radio').is('checked'), 'Please check a radio');
});

Upvotes: 0

jamesmortensen
jamesmortensen

Reputation: 34048

There are two main problems that I see here:

The id's on the input elements are not unique.

As per the spec, an id on any element on a page must be unique. In other words, you shouldn't use id="organizacion" 4 times like you are. This may or may not affect the ability for scripts to locate your elements, considering they'll likely stop at the first one, being implemented with the knowledge and understanding that id's must be unique.

Validity doesn't have any documentation supporting radio button validation.

I don't see any text fields in your HTML, and I don't see any documentation in Validity in regards to radio buttons. Thus, what you're trying to accomplish may not be possible with Validity.

As a final point, radio buttons are designed so that, in a group, one must always be selected. It's not possible to de-select a radio button. Thus, you should be sure that a default radio button is selected.

This may of course eliminate the need to make this a required field, since by default an option is already selected.

Upvotes: 3

Related Questions