I have a ractive button that needs to change the functions after each click.
const template1 = '<button type="button" id="advanceButton" on-click="@this.advance()">Step1</button>'
ractive = new Ractive({
el: '#container',
template: template1,
advance: function() {
$("#advanceButton").html("Step2");
//this.on-click change to advance2() //that that would be the desired behaviour
}
});
ractive.on({
advance2: function() {
$("#advanceButton").html("Step3");
//this.on-click change to advance3() //and so on...
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ractive/1.3.12/ractive.js"></script>
<div id="container"></div>
I tried to do it outside of ractive with $("#advanceButton").attr('onclick', 'advance2()') but despite the fact that it did not work either, I'd rather like to solve that inside ractive.
You could keep a value of current step and based on that call required function.
Hope this helps.