Wow, that’s clever
You should be able to use a fat arrow too:
Template.tpl.viewmodel
region: ->
reset: => @regionDropdown.dropdown('set text', 'some text')
yep, doing it right now! works nicely
btw, how do you make code colored in this forum?
I just use Markdown’s triple tick blocks.
Can we have multiple if
bindings on an element? Or multiple conditions for if
Use an expression “if: condition1 && condition2”
As we’re already at this topic, I know that we can use:
p($b="if: value1 == value2 && value3 == value4") you can see me!
But how can we do:
p($b="if: value1 < value2 && value3 > value4") you can see me too
I get:
Jade syntax error: Expected tag name after `<`
Is it working for HTML?
I know it’s easy to work around with global helpers like isGreaterThan etc, but I’m just curious if it’s possible to use natively.
Hello,
I was just wondering how you go about using a schema and doing validates with this package? How would this work with simpleSchema for example?
Cheers
For me it works with Simple Schema and even Autoform without any problems. What potential issue could you have in mind?
@brajt Do you create a new context everytime (mySchema.newContext();
). I know that VM and SimpleSchema work together, but I was struggeling how I can handle error messages easily without writing own helpers. I’ve just switched to Astronomy because it’s error object was much simpler and easier to use with ViewModel.
That my friend is what we call a “bug”. I’ll check it out.
@brajt That’s a problem with Jade. The following works as expected:
<body>
<div {{b "if: value1 < value2 && value3 > value4"}}>It works</div>
</body>
Template.body.viewmodel({
value1: 1,
value2: 2,
value3: 4,
value4: 3
});
And you can change a value in the console and the UI updates accordingly:
> ViewModel.findOne("body").value4(5)
Thanks. I’ll have to stay with global helpers then, but at least now I know one more use case when I can recommend Viewmodel when people ask “can I do that in Blaze?”
Hi @manuel,
Thank you for this awesome tool! Though, I haven’t used it yet but I think a lot of pain points in blaze are covered by VM.
I would like to ask if this is compatible to autoform?
@brajt looks like you’re the unofficial ambassador of VM Do you have experience integrating autoform and VM?
Thanks!
A bug with the Jade compiler, I think. I may look into it if I find the time. Refer to issue #7.
@dalgard thanks a lot!
@ajaxsoap I use Autoform with Viewmodel for the app I’m currently writing, because Autoform gives me cool Semantic UI form templates integration and more complex form templates by default. But with Viewmodel I don’t see the advantage of Autoform being as big as before, as putting forms together with Viewmodel is very easy.
What I didn’t manage to do yet is using Viewmodel properties in Autoform hooks. It would be great to learn how to do it, if anybody made it work.
Cool!
I guess, that’s the reason I’m asking, VM + autoform vs VM + normal form
. I haven’t had the time to dig deep on VM due to my current dev load but VM is in my roadmap
Thanks!
I don’t know if it’s a bug in VM, jade or spacebars but if: !condition1 && condition2
evaluates to true (element is displayed) if condition1 === false
whereas it should always evaluate to false
.
Same goes for ||.
if: !condition1 || condition1
doesnt display element when condition1 === true
whereas it should.
I’ll move the documentation to another place soon.