-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
🐛 Masks model updates #4175
base: main
Are you sure you want to change the base?
🐛 Masks model updates #4175
Conversation
Hey @ekwoka - can you provide a clearer explanation of what this PR is doing? Thanks. (also, clever approach: decorating the forceModelUpdate method) |
You got it! 👍 |
It shouldn't impact that at all. |
Alright, that's a still a problem then. Thanks for this PR though! |
c64ac10
to
017f0b1
Compare
Ran into this issue just now. Going to have to figure out an alternate solution until this PR is merged as I need the mask to apply both with manual and programmatic updates. |
017f0b1
to
0ddf556
Compare
When will this PR be merged? |
test('$mask should process the value when updated by x-model', | ||
[html` | ||
<div x-data="{value:55555}"> | ||
<input type="text" x-model=value x-mask:dynamic="$money($input)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<input type="text" x-model=value x-mask:dynamic="$money($input)"> | |
<input type="text" x-model="value" x-mask:dynamic="$money($input)"> |
@calebporzio The problem is that when we change the Alpine data using JS the mask won't apply to the changed value. The demo link that the author provided is obvious: <div
x-data="masked"
class="w-full flex gap-2 justify-center flex-col items-center"
>
<input
type="text"
x-model="value"
x-mask:dynamic="$money($input)"
class="p-2 text-center"
/>
<button
@click="value = 123000"
type="button"
class="py-2 px-4 bg-indigo-800 text-indigo-200 rounded-lg"
>
Update data value
</button>
</div> We have an input with an x-mask on it and a button that changes the input value when we click on it. |
Solves #3691
Problem
When a value modeled onto an input with x-mask is updated on the data side (not via the masked input itself), the mask is not processing and masking the value. Most commonly this will be common with $money where the programmatically updated value is likely to just be a raw number or number string.
Demo
Solution
This checks for and wraps the x-model forced update method to retrigger the masking on the value and push it back into the model.
Not exactly pretty. I can do a more significant refactoring of the directive to make this cleaner, but this basically shows what steps aren't being handled.
Tests
This includes a bespoke test, as well as passes a previous disabled test (which is now enabled) that seemed to run into this issue in a flaky manner