DmVinny
DmVinny

Reputation: 173

Get variable from alpine.js and add it to placeholder

I am trying to fetch a variable from an alpinejs format to put into placeholder of my input, the code is as follows:

<template x-for="(field, index) in fields" :key="index">
    <input type="text" name="sort" placeholder="<want to put index here>" />
</template>

Is this possible?

Upvotes: 3

Views: 3927

Answers (1)

Arpan Kc
Arpan Kc

Reputation: 938

Try this:

<template x-for="(field, index) in fields" :key="index">
    <input type="text" name="sort" x-bind:placeholder="index" />
</template>

Upvotes: 4

Related Questions