Skip to content

Dynamic x-mask broken when used together with wire:model #10377

Closed
alpinejs/alpine
#4852

Description

@CasEbb

Livewire version

v4.3.3

Laravel version

v13.18.0

PHP version

8.5.7

Browser and operating system

Chrome on macOS

Describe the issue you're experiencing

When dynamically determining x-mask for a text input, the mask fails to work properly when the field also has wire:model and x-mask changes inbetween renders.

Considering the example below:

  1. Starting with country 'FR' and postal code '12345' in a field masked '99999'
  2. Change the country to 'BE' and the postal code changes to '1234' adhering to the mask '9999'. The mask still works fine.
  3. Change the country back to 'FR' (check your web developer console to ensure that x-mask has been updated again) and type a number in the input. It won't show up. If you type the same number again, it will show up. If you type another number, the input is still limited to 4 numbers (instead of the expected 5).
  • This behaviour doesn't occur if the field doesn't have wire:model.
  • Bissecting shows this bug was introduced between v4.2.2 and v4.2.3 (presumably the Alpine update from v3.15.8 to v3.15.9)

Code snippets to reproduce the issue

<?php

use Livewire\Attributes\Computed;
use Livewire\Component;

new class extends Component {
    public string $country = 'FR';
    public string $postalCode = '12345';

    #[Computed]
    public function mask()
    {
        return $this->country === 'FR' ? '99999' : '9999';
    }
};

?>
<form wire:submit="save">
    <select wire:model.live="country">
        <option value="FR">France</option>
        <option value="BE">Belgium</option>
    </select>
    <input wire:model="postalCode" x-mask="{{ $this->mask }}">
    <button type="submit">Save</button>
</form>

Screenshots/screen recordings

No response

How do you expect it to work?

x-mask is supposed to work properly after changing between renders

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be removed if I haven't met the criteria above.

Activity

  1. joshhanley commented on Jul 1, 2026

    @joshhanley
    Member

    @CasEbb thanks for reporting! I've submitted a PR alpinejs/alpine#4852 with a fix.

  2. self-assigned this
    on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions