Replies: 10 comments 1 reply
-
I've implemented this myself with a custom Vue component, but I'll investigate if this is something we can bring into Splade. |
Beta Was this translation helpful? Give feedback.
-
Have you investigated? |
Beta Was this translation helpful? Give feedback.
-
Can you please give me a hint?
How can I repeat this with a variable
|
Beta Was this translation helpful? Give feedback.
-
I manage to do field repeater using Custom Form components (https://splade.dev/docs/custom-form-components). Here is the sample in <template>
<div>
<div v-for="(field, index) in fields" :key="index">
<input v-model="fields[index]" class="input w-full max-w-xs" />
<button class="btn btn-secondary" @click.prevent="removeField(index)">Remove</button>
</div>
<button @click.prevent="addField" class="btn btn-primary">Add Field</button>
</div>
</template>
<script setup>
import { ref } from "vue"
const emit = defineEmits(['update:modelValue'])
const fields = ref([''])
const addField = (event) => {
fields.value.push("")
emit('update:modelValue', fields.value)
}
const removeField = (index) => {
fields.value.splice(index, 1)
}
</script>
then add the component in blade template (ex: <x-layout>
<x-slot name="header">
<h1>Add Rental</h1>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
<div class="p-4 sm:p-8 bg-white shadow sm:rounded-lg">
<div class="max-w-xl">
<x-splade-form confirm method="post" :action="route('rental.store')">
<x-splade-input name="customer_name" label="Customer_name" />
<x-splade-input name="location" label="Location" />
<!-- Custom component -->
<Repeater v-model="form.repeat" />
<div class="pt-6">
<div class="flex space-x-2">
<x-splade-submit />
<Link class="btn btn-sm btn-secondary"
href="{{ route('rental.index') }}">Back</Link>
</div>
</div>
</x-splade-form>
</div>
</div>
</div>
</div>
</x-layout> The value will be store in array and you can get the input value in the controller by call public function store(Request$request)
{
...
dd($request->repeat);
...
} |
Beta Was this translation helpful? Give feedback.
-
This approach works very well! I'm surprised how flexible Splade is here. You can even pass the errors to your custom component, and merge all fields from a Splade Form Class:
The only downside is that I can't see a way to use existing Splade components (input, buttons) within my customrepeater, but it didn't take long to copy the styles from those and make my own vue inputs. |
Beta Was this translation helpful? Give feedback.
-
Hope splade can add this feature |
Beta Was this translation helpful? Give feedback.
-
But how to add default data in the vue repeater component? |
Beta Was this translation helpful? Give feedback.
-
If I wrap the vue component in x-splade-data it works but then it doesn't pass the data back to controller |
Beta Was this translation helpful? Give feedback.
-
I got it I just have to pass unguarded on the form |
Beta Was this translation helpful? Give feedback.
-
Renderless Custom Vue Component: Repeater.vue This component is a renderless custom Vue component designed to dynamically add and remove rows with input fields for name and URL. Usage: .blade.php <Repeater :form="form" />
|
Beta Was this translation helpful? Give feedback.
-
https://filamentphp.com/docs/2.x/forms/fields#repeater
By using Spade Form, can something like this be achieved in Splade?
Dynamically add or remove fields, means some time hasMany relation need to for CRUD purpose.
Beta Was this translation helpful? Give feedback.
All reactions