There was a lot wrong in existing code. The only thing that was working at all was html5 required
property on radios.
The context of this
within all the handlers is wrong, the code is obviously copy/pasted from original site, but set up is different.
The radio
class in plugin object doesn't exist, and plugin won't validate based on type=radio
.
Also $(document).ready(function{..
is same as $(function(){..
and there is never any reason to nest one in the other. There is no reason to have more than one document.ready
for this code at all.
Here is some working code:
$(document).ready(function () {
$('input[name="response1"]').change(function () {
var showDescription = $('#1yes').is(':checked');
$('#affirmative1')[showDescription ? 'show':'hide'](1000);
//$('.dependsRadio').prop('required', showDescription);
});
$('#myform').ipValidate({
/* this class "dependsRadio" added to textarea html to make validation work*/
dependsRadio:{
rule: function () {
var yesChecked=$('#1yes').is(':checked');
return yesChecked ? $(this).val() !='' :true;
},
onError: function () {
alert('textarea not valid')
},
onValid: function () {
}
},
/* class added to radio elements*/
radioClass: {
rule: function () {
return $('input[type=radio]:checked').length < 1 ? false : true;
},
onError: function () {
alert('radio not checked')
},
onValid: function () {
}
},
submitHandler: function () {
alert('form is valid');
return false;/* debug mode*/
}
});
});
DEMO: http://jsfiddle.net/VgG4M/1/
Strongly suggest in future using plugins with documentation which this one definitely has none