0

I try to get the click on a checkbox using RactiveJS, as follows:

HTML:

<input type='checkbox' on-change-input-click="toggle">

JS:

toggle : function(){
    treatment()
}

The toggle function never gets called.

Why would I like to catch the toggle event? Because once the checkbox toggled, other components must be changed. More precisely, this is a checkbox in a tree. Toggling a checkbox in a tree node toggles the descendants nodes.

Maybe there is another event than change, input or click I missed...

The complete code is in this fiddle.

2 Answers 2

3

Your fiddle is using version 0.3.7, in that version only proxy events are supported and there was no init event in which to subscribe, and there were no array methods on ractive itself. So you'd need to do something like:

ractive.on('toggle', function(){
    this.get("clicked").push("clicked!");
});

Latest is version is 0.6.1, but you still have an issue with your code. If you want to call a method on the ractive instance, you need to invoke it in the handler:

HTML:

<input type='checkbox' on-change="toggle()">

JS:

toggle: function(){
    treatment()
}

If you want to raise an event, you need to subscribe to that proxy name:

HTML:

<input type='checkbox' on-change="toggle">

JS:

oninit: function(){
    this.on('toggle', function(){
        treatment()
    });
}
2
  • I can't get my jsFiddle work, but my application works fine with both of your solutions. Thanks! Feb 19, 2015 at 15:08
  • You have moved the "on" outside of the block. I don't know why this works better, but this works. Thanks for the tip Feb 20, 2015 at 13:33
0

Try this: I made a JS Fiddle for you

HTML:

<input id="myID" type='checkbox' onchange="yourFunction()" />

JS:

function yourFunction() {
alert("changed");
}

https://jsfiddle.net/4kxrkubc/

1
  • I need RactiveJS to handle the event/function call, so this won't work for me. Thanks anyway Feb 19, 2015 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.