Sorry about the long and convoluted title, but I couldn’t summarize it better.
I have a simple model, with a property foo, initialized to null.
In my view, I don’t want to display an input field when foo is null or "", and have a button that says Add foo.
<a href="#" class="btn" {{action addFoo obj}}> Add foo </a>
{{#if obj.foo}}
{{view Ember.TextField valueBinding="obj.foo"}}
{{/if}}
Then in my action addFoo, I do:
obj.set('foo', 1);
and that will make the input field appear.
I have two problems with this approach:
1is really an arbitrary value, it doesn’t have any special meaning in my application.- If the user deletes
1because they want to type2, the input field will disappear before they have the time to type2.
Is there a better approach to this kind of user interaction?
I ended up adding a computed property to my model:
So that in my
handlebarstemplate I could do this:This way I can deal with
nullonly, and''will act as if the property is set and valid.