If you want to do this with an assistant, you cannot extend Ember.TextField , because extends Ember.Component and is not an assistant to Handlebars.
The way to do this with an assistant will be easier. Since you are using Ember-CLI, you can create a helper called "input-url" with the ember g helper input-url command, and you only need the code you need, this is the code in your formatValue() function:
helpers / url.js
// define patter globally so it not recreated each time the function is called var pattern = /^https{0,1}:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+/g; export function inputUrl(value) { if (pattern.test(value)) { return value; } if (!pattern.test('http://' + value)) { return value; } return 'http://' + value; }; export default Ember.Handlebars.makeBoundHelper(inputUrl);
And you can use it like:
{{input-url PASS_YOUR_URL_HERE}}
If the value you pass is the value of the value variable in the helper.
You can also create the component, as suggested by @Gaurav , using the exact code that you have above, only in the / input -url.js components instead and remove the auxiliary reason, because this is optional, you must also edit the corresponding component template. if you want it to display value with one descriptor expression:
templates / components / input-url.hbs
{{value}}
Use with the component will be:
{{input-url value=PASS_YOUR_URL_HERE}}
source share