From f50fca48e2031c42bf5bf0d1008472809dc2f636 Mon Sep 17 00:00:00 2001 From: Steve Hull Date: Tue, 10 May 2016 23:46:45 -0700 Subject: [PATCH] Abide: don't validate hidden fields, skip ignored fields at validation time --- js/foundation.abide.js | 7 ++- test/javascript/components/abide.js | 41 +++++++++++---- .../abide/hidden_and_ignored_fields.html | 51 +++++++++++++++++++ 3 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 test/visual/abide/hidden_and_ignored_fields.html diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 0196a4db3..3ff52a27a 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -29,7 +29,7 @@ class Abide { * @private */ _init() { - this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore]'); + this.$inputs = this.$element.find('input, textarea, select'); this._events(); } @@ -242,6 +242,11 @@ class Abide { 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')); diff --git a/test/javascript/components/abide.js b/test/javascript/components/abide.js index 78be9efd8..b476bfe92 100644 --- a/test/javascript/components/abide.js +++ b/test/javascript/components/abide.js @@ -1,20 +1,39 @@ +/* jslint mocha: true */ +/*global describe, it, before, beforeEach, after, afterEach, $, Foundation */ + describe('Abide', function() { var plugin; var $html; - // afterEach(function() { - // plugin.destroy(); - // $html.remove(); - // }); + afterEach(function() { + plugin.destroy(); + $html.remove(); + }); describe('constructor()', function() { - // it('', function() { - // $html = $('').appendTo('body'); - // plugin = new Foundation.Abide($html, {}); + it('stores the element & plugin options', function() { + $html = $('
').appendTo('body'); + plugin = new Foundation.Abide($html, {}); + + plugin.$element.should.be.an('object'); + plugin.options.should.be.an('object'); + }); + }); + + describe('validateInput()', function() { + it('returns true for hidden inputs', function() { + $html = $("
").appendTo("body"); + plugin = new Foundation.Abide($html, {}); + + plugin.validateInput($html.find("input")).should.equal(true); + }); + + it('returns true for inputs with [data-abide-ignore]', function() { + $html = $("
").appendTo("body"); + plugin = new Foundation.Abide($html, {}); - // plugin.$element.should.be.an('object'); - // plugin.options.should.be.an('object'); - // }); + plugin.validateInput($html.find("input")).should.equal(true); + }); }); -}); \ No newline at end of file +}); diff --git a/test/visual/abide/hidden_and_ignored_fields.html b/test/visual/abide/hidden_and_ignored_fields.html new file mode 100644 index 000000000..5c9bf34a8 --- /dev/null +++ b/test/visual/abide/hidden_and_ignored_fields.html @@ -0,0 +1,51 @@ + + + + + + + Foundation for Sites Testing + + + +
+

Abide: Hidden and Ignored Fields

+
+

This form has a hidden field and a required text field.

+

Errors should be displayed properly.

+ +
+ + This field is required + + + +
+
+
+

This form has a required text field and an ignored field that is ignored after page load.

+

The ignored field should be ignored.

+
+
+ + This field is required +
+
+ + You should never see this error! +
+ + +
+
+
+ + + + + + -- 2.47.2