vendor/assets/js/foundation.abide.js.es6 in foundation-rails-6.2.1.0 vs vendor/assets/js/foundation.abide.js.es6 in foundation-rails-6.2.3.0

- old
+ new

@@ -27,11 +27,11 @@ /** * Initializes the Abide plugin and calls functions to get Abide functioning on load. * @private */ _init() { - this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore]'); + this.$inputs = this.$element.find('input, textarea, select'); this._events(); } /** @@ -81,10 +81,14 @@ if (!$el.attr('required')) return true; var isGood = true; switch ($el[0].type) { + case 'checkbox': + isGood = $el[0].checked; + break; + case 'select': case 'select-one': case 'select-multiple': var opt = $el.find('option:selected'); if (!opt.length || !opt.val()) isGood = false; @@ -236,10 +240,15 @@ validated = false, customValidator = true, validator = $el.attr('data-validator'), equalTo = true; + // don't validate ignored inputs or hidden inputs + if ($el.is('[data-abide-ignore]') || $el.is('[type="hidden"]')) { + return true; + } + switch ($el[0].type) { case 'radio': validated = this.validateRadio($el.attr('name')); break; @@ -351,24 +360,29 @@ */ validateRadio(groupName) { // 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; + var valid = false, required = false; - // .attr() returns undefined if no elements in $group have the attribute "required" - if ($group.attr('required') === undefined) { - valid = true; - } - - // 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; } /** * Determines if a selected input passes a custom validation function. Multiple validations can be used, if passed to the element with `data-validator="foo bar baz"` in a space separated listed. @@ -396,10 +410,12 @@ $(`.${opts.labelErrorClass}`, $form).not('small').removeClass(opts.labelErrorClass); $(`.${opts.inputErrorClass}`, $form).not('small').removeClass(opts.inputErrorClass); $(`${opts.formErrorSelector}.${opts.formErrorClass}`).removeClass(opts.formErrorClass); $form.find('[data-abide-error]').css('display', 'none'); - $(':input', $form).not(':button, :submit, :reset, :hidden, [data-abide-ignore]').val('').removeAttr('data-invalid'); + $(':input', $form).not(':button, :submit, :reset, :hidden, :radio, :checkbox, [data-abide-ignore]').val('').removeAttr('data-invalid'); + $(':input:radio', $form).not('[data-abide-ignore]').prop('checked',false).removeAttr('data-invalid'); + $(':input:checkbox', $form).not('[data-abide-ignore]').prop('checked',false).removeAttr('data-invalid'); /** * Fires when the form has been reset. * @event Abide#formreset */ $form.trigger('formreset.zf.abide', [$form]);