Template helpers parametres allways typecasted as String #617
Comments
I've reproduced this here (using my own sessionEquals function): https://github.com/belisarius222/meteor-session-test Indeed, the arguments to the helper all show up as strings. My test used a global Handlebars helper, not template-specific. @raix I'd love to see your workaround for the other types. |
Well it's a simple one: Handlebars.registerHelper('sessionEquals', function (key, value) {
var myValue = Session.get(key); //Workaround Issue #617
if (typeof(myValue) === 'boolean') //Workaround Issue #617
return Session.equals(key, (value == 'true')); //Workaround Issue #617
return Session.equals(key, (myValue === +myValue)?+value:value); //Workaround Issue #617
//return Session.equals(key, value); //When Issue #617 is resolved
}); Just finished up writing tests and an example for |
Cool! Looking forward to seeing it. On Fri, Jan 18, 2013 at 3:10 AM, Morten N.O. Nørgaard Henriksen <
|
@belisarius222 Made a meteorite package, https://github.com/raix/Meteor-handlebar-helpers for now until docs in place |
I had a chance to sit down with @dgreensp and look at this today. He agrees this is not the correct behavior, integers and bools should be returned, not strings. It appears the conversion to string happens very early on in the processing chain. By the time it comes from our |
Thanks, well I'll have a look at the issue later maybe - at the moment the workaround does it's thing, though not optimal. Btw: I'm writing a At the moment my helper <template name="myTemplate">
...
{{#if bindStatus 'myTemplate'}} Yeah, I know this stuff should go on SO or IRC? though not much luck there Example of twoway databinding using the handlebar handlers - only js written is one line pointing the template towards a collection for db access and validation: <template name="hello">
<!-- New data -->
<input {{bind 'name'}} placeholder="Name"/>
<input {{bind 'email'}} type="email" placeholder="Email"/>
<button {{bindAction 'create'}} class="btn">Add</button>
<button {{bindAction 'cancel'}} class="btn">Cancel</button>
<br/>
<!-- Data -->
{{#each find 'testCol' '{}'}}
<input {{bind 'name'}} placeholder="Name"/>
<input {{bind 'email'}} type="email" placeholder="email"/>
<!-- Pr. Key validation -->
{{#with bindStatus 'hello' _id 'email'}}
{{#if this.invalid}} Email is invalid{{/if}}
{{#if this.required}} Email is required<br/>{{/if}}
{{/with}}
<button type="button" {{bindAction 'update'}} class="btn">Update</button>
<a {{bindAction 'cancel'}} class="btn">Cancel</a>
<input type="button" value="Delete" {{bindAction 'delete'}} class="btn"/>
<br/>
<!-- Pr. Record validation repport -->
{{#each bindStatus 'hello' _id}}
{{#if this.invalid}} {{this.keyName}} is invalid<br/>{{/if}}
{{#if this.required}} {{this.keyName}} is required<br/>{{/if}}
{{else}}
No bindStatus / validation errors
{{/each}}
{{/each}} <!-- EO find -->
<!-- Total Validation repport -->
{{#each bindStatus 'hello'}}
{{#if this.invalid}} {{this.keyName}} is invalid<br/>{{/if}}
{{#if this.required}} {{this.keyName}} is required<br/>{{/if}}
{{else}}
No bindStatus / validation errors
{{/each}}
</template> |
I've just completed a generel helper
{{sessionEquals}}
There are some issues involved:
For now I made a workaround for
number
andboolean
- but it creates a bit of unnessesary overheat.The text was updated successfully, but these errors were encountered: