Skip to content

Commit

Permalink
Merge pull request #99 from tristanls/master
Browse files Browse the repository at this point in the history
support for input:password, input:email, input:number, etc..
  • Loading branch information
arturadib committed Jan 31, 2013
2 parents 2a2a2c9 + 6ab3c24 commit da7e958
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agility.js
Expand Up @@ -576,7 +576,7 @@
}

// <input type="text">, <input>, and <textarea>: 2-way binding
else if ($node.is('input:text, textarea')) {
else if ($node.is('input:text, input[type!="search"], textarea')) {
// Model --> DOM
self.bind('_change:'+bindData.key, function(){
$node.val(self.model.get(bindData.key)); // this won't fire a DOM 'change' event, saving us from an infinite event loop (Model <--> DOM)
Expand Down
36 changes: 36 additions & 0 deletions test/public/core.js
Expand Up @@ -985,6 +985,21 @@
// obj.view.$().val('Joe Doee').keypress();
// equals(obj.model.get('name'), 'Joe Doee', 'search input: DOM --> Model binding OK');

var obj = $$({email:'mary@email.com'}, "<input type='email' data-bind='email' />");
equals(obj.view.$().val(), 'mary@email.com', 'email input: binding properly initialized');
obj.model.set({email:'joe@email.com'});
equals(obj.view.$().val(), 'joe@email.com', 'email input: Model --> DOM binding OK');

var obj = $$({num:42}, "<input type='number' data-bind='num' />");
equals(obj.view.$().val(), "42", 'number input: binding properly initialized');
obj.model.set({num:1337});
equals(obj.view.$().val(), "1337", 'number input: Model --> DOM binding OK');

var obj = $$({pass:'secret'}, "<input type='password' data-bind='pass' />");
equals(obj.view.$().val(), 'secret', 'password input: binding properly initialized');
obj.model.set({pass:'other secret'});
equals(obj.view.$().val(), 'other secret', 'password input: Model --> DOM binding OK');

obj = $$({a:true}, "<input type='checkbox' data-bind='a' />");
equals(obj.view.$().prop('checked'), true, 'checkbox input: binding properly initialized');
obj.model.set({a:false});
Expand Down Expand Up @@ -1027,6 +1042,27 @@
// obj.view.$().val('Joe Doee').keypress();
// equals(obj.model.get('name'), 'Joe Doee', 'search input: DOM --> Model binding OK');

var obj = $$({email:'mary@email.com',myAttr:'myAttr'}, "<input type='email' data-bind='email, myAttr myAttr' />");
equals(obj.view.$().val(), 'mary@email.com', 'email input: binding properly initialized');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');
obj.model.set({email:'joe@email.com'});
equals(obj.view.$().val(), 'joe@email.com', 'email input: Model --> DOM binding OK');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');

var obj = $$({num:42,myAttr:'myAttr'}, "<input type='number' data-bind='num, myAttr myAttr' />");
equals(obj.view.$().val(), '42', 'number input: binding properly initialized');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');
obj.model.set({num:1337});
equals(obj.view.$().val(), '1337', 'number input: Model --> DOM binding OK');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');

var obj = $$({pass:'secret',myAttr:'myAttr'}, "<input type='password' data-bind='pass, myAttr myAttr' />");
equals(obj.view.$().val(), 'secret', 'password input: binding properly initialized');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');
obj.model.set({pass:'other secret'});
equals(obj.view.$().val(), 'other secret', 'password input: Model --> DOM binding OK');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');

obj = $$({a:true,myAttr:'myAttr'}, "<input type='checkbox' data-bind='a, myAttr myAttr' />");
equals(obj.view.$().prop('checked'), true, 'checkbox input: binding properly initialized');
equals(obj.view.$().attr('myAttr'), 'myAttr', 'extra attribute set');
Expand Down

0 comments on commit da7e958

Please sign in to comment.