Skip to content

alpine ajax breaks after adding second input in the form #145

@sedyh

Description

@sedyh

Hello, I don't understand why alpine ajax is replacing fine this fragment:

<form 
    id="totp-1" 
    x-target method="post" 
    action="/totp/1"
    x-data x-ref="digits"
>
    <input 
        id="digit-1"
        name="digit-1"
        type="text" 
        maxlength="1"
        @input="if ($el.value) $focus.within($refs.digits).next()" 
        @keyup.enter="$el.form.submit()"
    />
</form>

But it breaks and do full reload when the server returns this:

<form 
    id="totp-1" 
    x-target method="post" 
    action="/totp/1"
    x-data x-ref="digits"
>
    <input 
        id="digit-1"
        name="digit-1"
        type="text" 
        maxlength="1"
        @input="if ($el.value) $focus.within($refs.digits).next()" 
        @keyup.enter="$el.form.submit()"
    />
    <input 
        id="digit-2"
        name="digit-2"
        type="text" 
        maxlength="1"
        @input="if ($el.value) $focus.within($refs.digits).next()" 
        @keyup.enter="$el.form.submit()"
    />
</form>

And this will work again:

<form 
    id="totp-1" 
    x-target method="post" 
    action="/totp/1"
    x-data x-ref="digits"
>
    <input 
        id="digit-1"
        name="digit-1"
        type="text" 
        maxlength="1"
        @input="if ($el.value) $focus.within($refs.digits).next()" 
    />
    <input 
        id="digit-2"
        name="digit-2"
        type="text" 
        maxlength="1"
        @input="if ($el.value) $focus.within($refs.digits).next()" 
    />
    <button style="display: none;"></button>
</form>

Can I debug this behavior somehow? I don't see any errors in console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions