Skip to content

Commit

Permalink
[BUGFIX beta] Fix initial render of {{input type=bound}} for checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amiel Martin committed Aug 6, 2014
1 parent 9ded26c commit 6fb7812
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
13 changes: 10 additions & 3 deletions packages/ember-handlebars/lib/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ import Ember from "ember-metal/core"; // Ember.assert
// var emberAssert = Ember.assert;

import EmberHandlebars from "ember-handlebars-compiler";
import { handlebarsGet } from "ember-handlebars/ext";
var helpers = EmberHandlebars.helpers;
/**
@module ember
@submodule ember-handlebars-compiler
*/

function _resolveOption(context, options, key) {
if (options.hashTypes[key] === "ID") {
return handlebarsGet(context, options.hash[key], options);
} else {
return options.hash[key];
}
}

/**
The `{{input}}` helper inserts an HTML `<input>` tag into the template,
Expand Down Expand Up @@ -192,11 +201,9 @@ export function inputHelper(options) {

var hash = options.hash,
types = options.hashTypes,
inputType = hash.type,
inputType = _resolveOption(this, options, 'type'),
onEvent = hash.on;

Ember.assert('You can only use a string as a `type` parameter, not a variable', types.type === 'STRING' || types.type === undefined);

delete hash.type;
delete hash.on;

Expand Down
23 changes: 16 additions & 7 deletions packages/ember-handlebars/tests/controls/checkbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,35 @@ test("It works", function() {
}, /you must use `checked=/);
});

QUnit.module("{{input type='checkbox'}} - prevent dynamic type", {
QUnit.module("{{input type=boundType}}", {
setup: function() {
controller = {
inputType: "checkbox",
isChecked: true,
};

checkboxView = EmberView.extend({
controller: controller,
inputType: "checkbox",
template: compile('{{input type=inputType}}')
template: compile('{{input type=inputType checked=isChecked}}')
}).create();

append();
},

teardown: function() {
destroy(checkboxView);
}
});

test("It works", function() {
expectAssertion(function() {
append();
}, /not a variable/);
test("should append a checkbox", function() {
equal(checkboxView.$('input[type=checkbox]').length, 1, "A single checkbox is added");
});

// Checking for the checked property is a good way to verify that the correct
// view was used.
test("checkbox checked property is updated", function() {
equal(checkboxView.$('input').prop('checked'), true, "the checkbox is checked");
});

QUnit.module("{{input type='checkbox'}} - static values", {
setup: function() {
Expand Down

0 comments on commit 6fb7812

Please sign in to comment.