Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] [VNumberInput] Click event support for increment / decrement buttons #20342

Closed
gayanSandamal opened this issue Aug 15, 2024 · 6 comments · May be fixed by #20366
Closed

[Feature Request] [VNumberInput] Click event support for increment / decrement buttons #20342

gayanSandamal opened this issue Aug 15, 2024 · 6 comments · May be fixed by #20366

Comments

@gayanSandamal
Copy link

Problem to solve

I tried to used this component to send API requests when on value update by typing and on clicking on the increment and decrement buttons.

According to my use case I wanted to throttle the keyup event separately and emit right after clicking on the increment / decrement buttons.

But as per the current implementation increment / decrement value change fetched under @update:model-value

Proposed solution

I propose to add something like below where we can separately handle the click event on increment / decrement buttons

@click:increment / @click:decrement or one event for both

@gayanSandamal gayanSandamal changed the title [Feature Request] [Feature Request] [VNumberInput] Click event support for increment / decrement buttons [Feature Request] [VNumberInput] Click event support for increment / decrement buttons Aug 15, 2024
@J-Sek
Copy link
Contributor

J-Sek commented Aug 20, 2024

Is it some kind of server-side validation scenario?
Let me know what do you think about this example

@gayanSandamal
Copy link
Author

Is it some kind of server-side validation scenario? Let me know what do you think about this example

Hi @J-Sek thanks for picking up this issue and replying. I checked the example you provided and that's really helpful but in my scenario,

  1. User needs to press enter or blur the field to update the value (send API request with the newly entered value) after typing.
  2. Or user can click increment / decrement buttons send the API request right away with the newly changed value.

That's why I need to handle the increment and decrement button change separately.

@J-Sek Please let me know if you need further clarifications

@KaelWD
Copy link
Member

KaelWD commented Aug 20, 2024

You probably want to respond to keyboard up/down too right? Would watch(count, (a, b) => { if (Math.abs(a - b) === 1) run() }) solve your problem?

@J-Sek
Copy link
Contributor

J-Sek commented Aug 20, 2024

@gayanSandamal OK, so it is not the validation, but a "send to the backend" and you want to handle up/down control clicks (not the keybroad actions) without waiting for blur because in the user's mind he is not typing and expects results to be effective immediately.

VNumberInput captures clicks on up/down controls, so there is no way to get this behavior. I needed to swap component with rudimentary implementation for this example to work. Please excuse poor debounce.. in real life, you would probably need something better to handle race conditions.

@gayanSandamal
Copy link
Author

You probably want to respond to keyboard up/down too right? Would watch(count, (a, b) => { if (Math.abs(a - b) === 1) run() }) solve your problem?

When I was developing our component I did something similar to what you mentioned above to achieve the expected behaviour

https://github.com/FlowFuse/node-red-dashboard/blob/6015c0f9fadc39bcc79dae28c40dbc538c2a92a5/ui/src/widgets/ui-number-input/UINumberInput.vue#L144

@gayanSandamal
Copy link
Author

@gayanSandamal OK, so it is not the validation, but a "send to the backend" and you want to handle up/down control clicks (not the keybroad actions) without waiting for blur because in the user's mind he is not typing and expects results to be effective immediately.

VNumberInput captures clicks on up/down controls, so there is no way to get this behavior. I needed to swap component with rudimentary implementation for this example to work. Please excuse poor debounce.. in real life, you would probably need something better to handle race conditions.

Thanks a lot @J-Sek I've achieved the expected behaviour by doing something hackie here and it's similar that @KaelWD showed in his comment because I was in a rush to get that done.

I will try with your new example because it's more cleaner than what I've done at the moment.

Also I will close this issue as it's resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants