These are chat archives for canjs/canjs

16th
Jun 2017
Justin Meyer
@justinbmeyer
Jun 16 2017 15:22
DoneJS Contributor Meeting: https://www.youtube.com/watch?v=Zpl_0G-IRZk
Yeswanth Raghav T
@tyraghav
Jun 16 2017 16:00
Hi
($click)
Yeswanth Raghav T
@tyraghav
Jun 16 2017 16:07
($click)=fun() in the stache works well if the function fun() is in viewModal of can.component
Frank Lemanschik
@frank-dspeed
Jun 16 2017 16:08
yes that most times don't works
Yeswanth Raghav T
@tyraghav
Jun 16 2017 16:08
Is there anyway to do the same type of binding when the fun() needs to be called from can.control
??
Brad Momberger
@bmomberger-bitovi
Jun 16 2017 16:12
If a can-control is creating a template with a binding, you should pass the function as part of the object that renders the template.
Assuming that you have something in a can-control like this:
init: function(opts) {
  this.element.appendChild(templateRenderfunction(this.options));
}
you can, for example, add the handler function to the static defaults
can.Control.extend("myControl", {
  defaults: {
    myClickHandler: function() {
       // handle a click based on whatever is passed in
    }
  }
}, { ... /*prototype props*/ });
Yeswanth Raghav T
@tyraghav
Jun 16 2017 16:22
Sorry,
Function was inside can.control
Can
Can.control.extend
Something like this
Can.control.extend(fun:function(object){})
Sorry for the typo errors
Brad Momberger
@bmomberger-bitovi
Jun 16 2017 16:28
How are you rendering the template that has the binding?
Yeswanth Raghav T
@tyraghav
Jun 16 2017 16:50
We are using a ca.model to render
Can.model
Brad Momberger
@bmomberger-bitovi
Jun 16 2017 17:04
What I'd recommend is creating a can-view-scope to pass to the template.
So then you can add two scope contexts: one that has functions to bind on (it can be the can-control prototype for simplicity), and the other is the model
so it would look like: templateRenderFunction(new canViewScope(this).add(modelInstance))
Yeswanth Raghav T
@tyraghav
Jun 16 2017 17:29
Ok
I will check it
Thank you
Yeswanth Raghav T
@tyraghav
Jun 16 2017 22:48
Does this.validate
Yeswanth Raghav T
@tyraghav
Jun 16 2017 22:57
Does this.validate always need to be init function or is there a way to validations to be in other functions...??
I want the validations to take place when I call them