Skip to content

[BUG] Data binding on x-post sets only on initial #2

@jinnodeleon

Description

@jinnodeleon

alpine-js: 3.13.10
alpine-requests: 1.0.4

<!-- problem -->
    <form x-data="{sample: ''}">
      <input type="text" x-model="sample" />
      <span x-text="sample"></span>
      <!-- binds only to empty sample property -->
      <button
        type="button"
        x-post="{route: '/api', body: JSON.stringify({sample}), headers: {'content-type': 'application/json'}}"
      >
        Like
      </button>
    </form>
<!-- workaround -->
    <form
      x-data="{sample: ''}"
      @submit.prevent="$post({route: '/api', body: JSON.stringify({sample}), headers: {'content-type': 'application/json'}})"
    >
      <input type="text" x-model="sample" />
      <span x-text="sample"></span>
      <button type="submit">Like</button>
    </form>

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