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

Introduce reusable number input field with delta support #18531

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eryon
Copy link
Contributor

@eryon eryon commented Mar 12, 2025

Expands on the existing input[data-allow-delta] to support keyboard delta (ArrowUp/Down) and (eventually) mousewheel support, specifically for editable character sheet fields such as XP, special resources, and HP.

@eryon
Copy link
Contributor Author

eryon commented Mar 12, 2025

@CarlosFdez I believe you're the right person to ping on this. It is a draft intended to show a possible solution for #18472. I'm proposing to extend the data-allow-delta attribute already in place, and introduce the pattern of adding min and max to allow the generic delta utility to work safely. If this makes sense, I can also add mouse-wheel deltas and apply it to the HP field.

}

if (triggerChange) {
$(input).trigger("change");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trigger does not appear to be anywhere else in the system, but the base Item sheet does programmatically dispatch a change event (here). I want to clarify that it needs to be done this way - or a standard Event with bubbling enabled - because of the way jQuery is internally (in the Foundry form application) setup to catch the data submission and actually apply the value changes to the data model.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a sheet helpers you could probably stick this in, but if this is possible with a regular event ideally use that instead, we're trying to get off jquery (core will eventually do so as well).

I'm wondering how well throttling the change would work, so that repeated hits down submit immediately and it behaves "smoother". Maybe a future consideration.

@@ -34,7 +34,7 @@
</div>
<div class="exp-data">
<div class="exp-input">
<input name="system.details.xp.value" type="text" value="{{data.details.xp.value}}" data-dtype="Number" data-allow-delta placeholder="0" size="4" />
<input name="system.details.xp.value" type="text" value="{{data.details.xp.value}}" data-dtype="Number" data-allow-delta data-min="0" data-max="{{data.details.xp.max}}" placeholder="0" size="4" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure but there is probably a valid use case in not having a max, due to spillover.

@CarlosFdez
Copy link
Collaborator

Repurposing data-allow-delta sounds fine to me

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

Successfully merging this pull request may close these issues.

2 participants