From: jk Date: Fri, 13 May 2016 11:44:41 +0000 (+0200) Subject: v6.2.2 fixes abide radio check if only one radio is required X-Git-Tag: v6.2.2-rc2~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df39d561fbdb9533e836802abf010cd9e5cf4ed2;p=thirdparty%2Ffoundation%2Ffoundation-sites.git v6.2.2 fixes abide radio check if only one radio is required --- diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 3ff52a27a..5c8750da3 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -362,19 +362,24 @@ class Abide { // If at least one radio in the group has the `required` attribute, the group is considered required // Per W3C spec, all radio buttons in a group should have `required`, but we're being nice var $group = this.$element.find(`:radio[name="${groupName}"]`); - var valid = false; - - // .attr() returns undefined if no elements in $group have the attribute "required" - if ($group.attr('required') === undefined) { - valid = true; - } + var valid = false, required = false; - // For the group to be valid, at least one radio needs to be checked + // For the group to be required, at least one radio needs to be required $group.each((i, e) => { - if ($(e).prop('checked')) { - valid = true; + if ($(e).attr('required')) { + required = true; } }); + if(!required) valid=true; + + if (!valid) { + // For the group to be valid, at least one radio needs to be checked + $group.each((i, e) => { + if ($(e).prop('checked')) { + valid = true; + } + }); + }; return valid; } diff --git a/test/visual/abide/abide-radio.html b/test/visual/abide/abide-radio.html index 14bc55fa2..56debd8be 100644 --- a/test/visual/abide/abide-radio.html +++ b/test/visual/abide/abide-radio.html @@ -30,6 +30,27 @@
+

This form has one required radio button. If you try to submit without picking one, it + should show an error. When you then pick one, the error should clear and let you submit.

+
+
+

This form has errors.

+
+
+ Fieldset Label + + + + + + +
+ + +
+ +
+

This form has optional radio buttons. It should let you submit with or without picking one.