_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

Increment/Decrement uses the value of the first input

Open storeman opened this issue 1 year ago • 7 comments

On a click action and want to increment values of all inputs and reset the closest input to 0.

I created a fiddle to demonstrate: https://jsfiddle.net/oj6c53bt/1/

I expect all inputs to have unique values at some point, but all values are synced with the first input of the selection.

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://unpkg.com/[email protected]"></script>

</head>
<body>
    <span _="on click
          increment the value of <input/>
          set the value of the next <input/> to 0">Click me third</span>
    <input type="number"
          value="0"/>
  <br/>
    <span _="on click
          increment the value of <input/>
          set the value of the next <input/> to 0">Click me second</span>
    <input type="number"
          value="0"/>
  <br/>
    <span _="on click
          increment the value of <input/>
          set the value of the next <input/> to 0">Click me first</span>
    <input type="number"
          value="0"/>
</body>
</html>

storeman avatar Jun 27 '23 15:06 storeman

I can also confirm i have a similar issue.

cipriano200 avatar Jul 02 '23 12:07 cipriano200

Thanks to your working example. I also was struggling to get it working with input values. Maybe you will also find something useful from my example as return https://jsfiddle.net/8d0jv1sw/

maybe you need to get the value before doing something.

get the (value of the next <input/>) as an Int increment it then set the value of the next <input/> to it

FDiskas avatar Aug 10 '23 20:08 FDiskas

@FDiskas I have a different use case. I want all the inputs to increase their own value. I've simplified the example, because my first example contained some noise

https://jsfiddle.net/rmuvcbx8/

storeman avatar Aug 11 '23 09:08 storeman

There is a good candidate https://hyperscript.org/expressions/you/ on click tell <input/> increment value of yourself bet result is the same :/ will dig in to it

FDiskas avatar Aug 11 '23 11:08 FDiskas

I landed only on one solution https://jsfiddle.net/eu29kdtr/ Send an event to elements and on that event on each element do something

FDiskas avatar Aug 11 '23 11:08 FDiskas

Also accidentally found yet another way on click repeat for x in <input/> increment the value of x end

FDiskas avatar Aug 11 '23 11:08 FDiskas

definitely a bug, will try to fix for the next release

1cg avatar Oct 08 '23 00:10 1cg