-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stache conditionals within custom attributes break in 2.3.0-pre.2 #1770
Comments
I'm surprised this was working before. Especially as I'm not sure how the parsing rules might have changed. I'll have to see what happens in 2.6 with this code. |
It's probably caused by the change to the regexes to accommodate the new binding syntaxes. |
This is caused by this code: https://github.com/bitovi/canjs/blob/v2.3.0-pre.2/view/stache/stache.js#L278 This was added so we can differentiate between two way
does something different than:
I'm not sure what to do with this. In the future, I'd like to replace
With this, there's currently no "meta" way of providing the name of the attribute that should be two way bound. Although, this would be interesting. For example, perhaps:
Would let you pass a renderer's output value as the property to be two-way bound. Unfortunately, I don't think this is something we can support in 2.3. Can-value was never intended to work this way. Instead, it would be good to find a work around. |
Alright, I've updated my code to get around this. While testing the upgrade again, I found that the following also no longer works: <select can-value="{model}">
<option value="Person">Person</option>
<option value="Car">Car</option>
</select>
<input type="text" auto-complete="{{ model }}"> In this case, I get the string A point of inconsistency that bothers me is that I can have helper attributes rendered with stache but not the main custom attribute itself. For example, this is how I might use a datepicker: <input type="text" can-value="{minDate}" date-picker>
<input type="text" can-value="{maxDate}" date-picker>
<input type="text" can-value="{myDate}" date-picker
dp-min-date="{{ minDate }}"
dp-max-date="{{ maxDate }}"> The |
@dylanrtt how about instead of:
We support a viewModel: {
nameUpdateProperty: function(){
return ( this.attr("contact") ? "contact." : "")+"name"
}
}
|
@dylanrtt regarding your last comment, I'm not entirely clear what you are saying:
Are you sure? That seems like a bug if you do.
Yes, this is why I would like to standardize on having things registered with
This way, at least by looking at a template, it would be obvious. |
So, this wouldn't be a problem if we had something other than
The problem is that
So, we simply wanted to make the same thing work for custom attributes, but remove the limitation of having to go to a string. But this turns off stache processing inside custom attributes. |
Actually, a problem with all of this:
Is that we'd have to be writing out |
Seems reasonable.
If http://jsbin.com/qarafoqugu/edit?html,js,console,output
I don't think it's necessary to support more complex expressions like More complicated examples like below could be handled in the view model. <div can-click="{{#if shown}}hide{{else}}show{{/if}}"></div> |
@dylanrtt well, I think we are going to propose something like angular 2.0's view binding syntaxes to fix this problem. Fundamentally, I'd like to keep stache able to run in any attribute. We can support this by moving the decorators from the attribute value, to the attribute name. I'm creating an issue for discussion. There's lots of discussion going on starting here: https://gitter.im/bitovi/canjs?at=55f32a416fe7b2a123eb04d0 |
The following is possible in 2.2.6:
This is helpful in situations where the context in which a template is rendered is dynamic. I am aware that can-value doesn't actually listen to changes to the attribute so it's not possible to change the field after the template is rendered, but it does work for making the initial render dynamic.
However, it seems to breaks the parser in 2.3.0-pre.2 (only version I tested since 2.2.6) on view/stache/text_section.js#L29 and/or view/stache/utils.js:32. I don't know if there are plans to fix it before release but figured I would bring it up as soon as possible.
I have a feeling that some of you might say doing it this way is bad. Perhaps. If you guys do want to continue to support it, I can make a jsbin to reproduce the bug. If not, I can fix my code.
The text was updated successfully, but these errors were encountered: