Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Fixes
- Fix ``pat-auto-scale`` not correctly rescaling after fullscreen changes. Fixes #673
- Fix heisenbug with pat-scroll on testruns.
- Fix minimum input length default so that you can display select results already on click.
- Fix ``pat-validation`` to not skip ``pat-autosuggest`` inputs even though they're
hidden. Fixes #683


## 3.0.0a5 - unreleased
Expand Down
4 changes: 4 additions & 0 deletions src/pat/validation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
/>
</label>

<label>Food preference
<input id="a1" name="a1" class="pat-autosuggest" placeholder="Pick some fruit" required="required" data-pat-autosuggest="words: Apples, Oranges, Pears, Bananas; maximum-selection-size: 1" type="text"></input>
</label>

<fieldset class="buttons">
<button class="pat-button">Test</button>
</fieldset>
Expand Down
20 changes: 20 additions & 0 deletions src/pat/validation/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,30 @@ define(["pat-registry", "pat-validation"], function(registry, pattern) {
'<form class="pat-validation">'+
'<input type="text" name="name">'+
'</form>');
pattern.init($el);
$el.find(':input').trigger('change');
expect($el.find('em.warning').length).toBe(0);
});

it("validates required pat-autosuggest inputs on form submit", function() {
var $el = $(
'<form class="pat-validation">'+
'<input type="hidden" name="name" required="required" class="pat-autosuggest" data-pat-autosuggest="words: one, two">'+
'</form>');
pattern.init($el);
$el.submit();
expect($el.find('em.warning').length).toBe(1);

// Check that validation passes when required is not here.
$el = $(
'<form class="pat-validation">'+
'<input type="hidden" name="name" class="pat-autosuggest" data-pat-autosuggest="words: one, two">'+
'</form>');
pattern.init($el);
$el.submit();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need another pattern.init($el) here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, yes it does. checked it and added it myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes then we probably also need it in the previous test which I copied this from...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, also added it there.

expect($el.find('em.warning').length).toBe(0);
});

it("validates required inputs with HTML5 required attribute style", function() {
var $el = $(
'<form class="pat-validation">'+
Expand Down
2 changes: 1 addition & 1 deletion src/pat/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ define([
// Ignore invisible elements (otherwise pat-clone template
// elements get validated). Not aware of other cases where this
// might cause problems.
var $single = this.$inputs.filter(':visible:enabled:not(:checkbox):not(:radio)');
var $single = this.$inputs.filter(':visible:enabled:not(:checkbox):not(:radio), .pat-autosuggest:not(:visible)');
var group_names = this.$inputs
.filter(':enabled:checkbox, :enabled:radio')
.map(function () { return this.getAttribute('name'); });
Expand Down