-1

Using AlpineJS I need to change the values of 1 or 2 variables based on a condition:

<button x-on:click="step < 4 ? step++; step++; done=true">Done</button>

However this is not working. Can this be done inside x-on:click?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

1 Answers1

0

it looks like your ternary statement formatting may be causing an issue here. I would first rule this out by changing the ; to a :. Additionally,I'm adding the step +=2 to replicate the ternary false conditional action. which by the looks of it you are trying to do? You may have to adjust the logic for this, as I found the function you are trying to accomplish unclear (a common problem with ternary statements).

<button x-on:click="step < 4 ? step+=2 : step++; done=step > 4;">Done</button>

I tested this method using onclick hook:

<button onclick="step < 4 ? step+=2 : step++; done=step-1 > 4;">Done</button>

Devin Sag
  • 79
  • 5