Skip to content

Commit

Permalink
Fallback to "-text-field" component name for unrecognized input type
Browse files Browse the repository at this point in the history
Previously, using an input type not in the map (such as "email") would
cause an exception. This renames the `classification` var to more
expressive `componentNameMap`, and turns the map into a whitelist of
non-default component names only. Any value of "type" not in that map (or
no value for "type") will use the default "-text-field" component name.
  • Loading branch information
bantic committed May 1, 2015
1 parent 5725b5c commit 5a1c5e1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/ember-htmlbars/lib/keywords/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import Ember from "ember-metal/core";

export default {
setupState(lastState, env, scope, params, hash) {
var type = env.hooks.getValue(hash.type) || 'text';
var type = env.hooks.getValue(hash.type);
var componentName = componentNameMap[type] || defaultComponentName;

Ember.assert("{{input type='checkbox'}} does not support setting `value=someBooleanValue`;" +
" you must use `checked=someBooleanValue` instead.", !(type === 'checkbox' && hash.hasOwnProperty('value')));

return { componentName: classification[type] };
return { componentName };
},

render(morph, env, scope, params, hash, template, inverse, visitor) {
Expand All @@ -20,8 +21,8 @@ export default {
}
};

var classification = {
'text': '-text-field',
'password': '-text-field',
var defaultComponentName = "-text-field";

var componentNameMap = {
'checkbox': '-checkbox'
};

5 comments on commit 5a1c5e1

@juggy
Copy link
Contributor

@juggy juggy commented on 5a1c5e1 Jun 2, 2015

Choose a reason for hiding this comment

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

Why not expose componentNameMap as a global config to enable custom inputs using the same convenient {{input prop type="custom-comp"}} ?

@bantic
Copy link
Member Author

@bantic bantic commented on 5a1c5e1 Jun 3, 2015

Choose a reason for hiding this comment

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

@juggy Not sure exactly what you are asking. Using another type should "just work". E.g. {{input type="color"}} should be fine.

@juggy
Copy link
Contributor

@juggy juggy commented on 5a1c5e1 Jun 3, 2015

Choose a reason for hiding this comment

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

type=date-picker to load the component date-picker for example with the value and properties set. But now I realise this is just sugar that might not be good in the long run. Just call the component directly.

I guess what bugs me here is that input either create a checkbox or a textfield, you also have textarea to create a text area. At the end we should get rid of all that and just call the components. Another discussion altogether. So nevermind for now.

@rwjblue
Copy link
Member

@rwjblue rwjblue commented on 5a1c5e1 Jun 3, 2015

Choose a reason for hiding this comment

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

@juggy - {{textarea}} creates a <textarea>

@bantic
Copy link
Member Author

@bantic bantic commented on 5a1c5e1 Jun 3, 2015

Choose a reason for hiding this comment

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

@juggy The type="checkbox" isn't actually intended to only be sugar to simplify creation of check box inputs. It's to reflect the fact that both text inputs and check box inputs are the same html tag (input) but have somewhat different semantics. The meaning of the value property is somewhat different between the two, and a checkbox input has a boolean checked property that is meaningless for text inputs. For custom inputs making your own component would definitely be the best way to go (i.e. {{calendar-date-picker-input}}).

Please sign in to comment.