whatgoodisaroad / validity

Client-Side Validation for jQuery
http://whatgoodisaroad.github.io/validity/
132 stars 75 forks source link

how to make radio button require #67

Closed GNyuu closed 9 years ago

GNyuu commented 9 years ago

Hi, I've been experimenting with the plugin for about half a day to make the selection of a radio button group required...and no luck.

So far I have this:

$( 'input:radio[name=gender]' ) .assert( $("input:radio[name='gender']").is(":checked"), 'Please select your gender' );

But no error message comes up for the radio group. Please help as I'm utterly lost as to what I did wrong...

GNyuu commented 9 years ago

Found out what was wrong. Had to give an ID for the plugin to know where to place the error msg. There was a div wrapped around the radio button group so I slapped an ID on it (eg. genderOptions) and edited the code:

$( '#genderOptions' ) .assert( $("input:radio[name='gender']").is(":checked"), "Please select your gender" );