Skip to content

Commit

Permalink
Changed to an event listener pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarrell-vz committed Oct 20, 2014
1 parent 67ee18d commit 2e1d27b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
26 changes: 17 additions & 9 deletions lists/static/list.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
/*global $, test, equal */
/*global jQuery */
jQuery(document).ready(function ($) {

$(document).ready(function () {
$('input').on('keypress', function() {
$('.has-error').hide();
});
});
var bindEventListeners = function () {
$('input[name="text"]').on('keypress', function () {
$('.has-error').hide();
});

$('input[name="text"]').on('click', function() {
$('.has-error').hide();
});
};

$(document).ready(function () {
$('input').on('click', function() {
$('.has-error').hide();
$.extend(window, true, {
'Superlists': {
'Lists': {
'bindEventListeners': bindEventListeners
}
}
});
});

7 changes: 5 additions & 2 deletions lists/static/tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
/*global $, test, equal */

test("errors should be hidden on keypress", function() {
$('#id_text').trigger('keypress'); //
Superlists.Lists.bindEventListeners();
$('input[name="text"]').trigger('keypress'); //
equal($('.has-error').is(':visible'), false);
});

test("errors should be hidden on click", function() {
$('#id_text').trigger('click'); //
Superlists.Lists.bindEventListeners();
$('input[name="text"]').trigger('click'); //
equal($('.has-error').is(':visible'), false);
});


test("errors should be visible before keypress or click", function() {
equal($('.has-error').is(':visible'), true);
});
Expand Down

0 comments on commit 2e1d27b

Please sign in to comment.