Skip to content

Commit

Permalink
Added maxlength to TextSupport; added size to TextField; added rows a…
Browse files Browse the repository at this point in the history
…nd cols to TextArea
  • Loading branch information
dgeb committed Feb 29, 2012
1 parent 31f6780 commit 469aa5c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/ember-handlebars/lib/controls/text_area.js
Expand Up @@ -20,6 +20,9 @@ Ember.TextArea = Ember.View.extend(Ember.TextSupport,
classNames: ['ember-text-area'],

tagName: "textarea",
attributeBindings: ['rows', 'cols'],
rows: null,
cols: null,

/**
@private
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-handlebars/lib/controls/text_field.js
Expand Up @@ -20,7 +20,7 @@ Ember.TextField = Ember.View.extend(Ember.TextSupport,
classNames: ['ember-text-field'],

tagName: "input",
attributeBindings: ['type', 'value'],
type: "text"

attributeBindings: ['type', 'value', 'size'],
type: "text",
size: null
});
3 changes: 2 additions & 1 deletion packages/ember-handlebars/lib/controls/text_support.js
Expand Up @@ -15,9 +15,10 @@ Ember.TextSupport = Ember.Mixin.create(

value: "",

attributeBindings: ['placeholder', 'disabled'],
attributeBindings: ['placeholder', 'disabled', 'maxlength'],
placeholder: null,
disabled: false,
maxlength: null,

insertNewline: Ember.K,
cancel: Ember.K,
Expand Down
43 changes: 41 additions & 2 deletions packages/ember-handlebars/tests/controls/text_area_test.js
Expand Up @@ -66,11 +66,50 @@ test("input placeholder is updated when setting placeholder property of view", f
textArea.append();
});

equal(textArea.$().attr('placeholder'), "foo", "renders text field with placeholder");
equal(textArea.$().attr('placeholder'), "foo", "renders text area with placeholder");

Ember.run(function() { set(textArea, 'placeholder', 'bar'); });

equal(textArea.$().attr('placeholder'), "bar", "updates text field after placeholder changes");
equal(textArea.$().attr('placeholder'), "bar", "updates text area after placeholder changes");
});

test("input maxlength is updated when setting maxlength property of view", function() {
Ember.run(function() {
set(textArea, 'maxlength', '300');
textArea.append();
});

equal(textArea.$().attr('maxlength'), "300", "renders text area with maxlength");

Ember.run(function() { set(textArea, 'maxlength', '400'); });

equal(textArea.$().attr('maxlength'), "400", "updates text area after maxlength changes");
});

test("input rows is updated when setting rows property of view", function() {
Ember.run(function() {
set(textArea, 'rows', '3');
textArea.append();
});

equal(textArea.$().attr('rows'), "3", "renders text area with rows");

Ember.run(function() { set(textArea, 'rows', '4'); });

equal(textArea.$().attr('rows'), "4", "updates text area after rows changes");
});

test("input cols is updated when setting cols property of view", function() {
Ember.run(function() {
set(textArea, 'cols', '30');
textArea.append();
});

equal(textArea.$().attr('cols'), "30", "renders text area with cols");

Ember.run(function() { set(textArea, 'cols', '40'); });

equal(textArea.$().attr('cols'), "40", "updates text area after cols changes");
});

test("value binding works properly for inputs that haven't been created", function() {
Expand Down
26 changes: 26 additions & 0 deletions packages/ember-handlebars/tests/controls/text_field_test.js
Expand Up @@ -73,6 +73,32 @@ test("input placeholder is updated when setting placeholder property of view", f
equal(textField.$().attr('placeholder'), "bar", "updates text field after placeholder changes");
});

test("input maxlength is updated when setting maxlength property of view", function() {
Ember.run(function() {
set(textField, 'maxlength', '30');
textField.append();
});

equal(textField.$().attr('maxlength'), "30", "renders text field with maxlength");

Ember.run(function() { set(textField, 'maxlength', '40'); });

equal(textField.$().attr('maxlength'), "40", "updates text field after maxlength changes");
});

test("input size is updated when setting size property of view", function() {
Ember.run(function() {
set(textField, 'size', '30');
textField.append();
});

equal(textField.$().attr('size'), "30", "renders text field with size");

Ember.run(function() { set(textField, 'size', '40'); });

equal(textField.$().attr('size'), "40", "updates text field after size changes");
});

test("input type is configurable when creating view", function() {
Ember.run(function() {
set(textField, 'type', 'password');
Expand Down

0 comments on commit 469aa5c

Please sign in to comment.