Reputation: 2497
I have a huge ember application and I'm trying to create a global variable/constant that I can use to set the default sizes of input fields. To be clear this is size as in the number of characters that can be entered, not size as in the CSS pixel size. How can I register a global variable such that instead of doing
{{input placeholder="Name..." maxlength=150}}
I can just do
{{input placeholder="Name..." maxlength=DefaultLength}}
Upvotes: 1
Views: 74
Reputation: 12872
You can reopen Ember.TextField
and update maxlength
property so that this value will be applicable all input helper.
Ember.TextField.reopen({
maxlength:250
});
Upvotes: 2
Reputation: 6542
You can use a helper for that. Example:
import Ember from 'ember';
const VALUES = {
DefaultLength: 150
}
export function valuesHelper(params/*, hash*/) {
return VALUES[params[0]];
}
export default Ember.Helper.helper(valuesHelper);
Will need some polishing, but should give you the idea.
Feel free to check the ember-twiddle.
Upvotes: 1