Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahr's avatar
Level 10

How to pass date-picler tag to input type hidden?

I have a date like this:

<date-picker type="date" id="inputDate" name="date" value="{{ old('date') }}" format="jYYYY-jMM-jDD" v-model="date"></date-picker>

How to pass date in the hidden field?

<input type="text" name="inputDate" id="inputDate">

script

<script>
    let product_id = "{{ $product->id }}";
    let warranty_id = "{{ $warranty->id }}";
    const app = new Vue({
        el: '#app',
        data: {
            dates: [],
            products: [],
            warranties: [],
            date: '',
            product_id: product_id,
            warranty_id: warranty_id,
        },
        watch: {
            date(newDate) {
                axios.get('{{ route('products.warranties.types.create', [$product, $warranty]) }}', {
                    product_id: this.product_id,
                    warranty_id: this.warranty_id,
                })
                    .then(response => {
                        const showType = document.getElementById('showType');
                        const inputDate = document.getElementById('inputDate');
                        showType.innerHTML = response.data;
                        inputDate.value = newDate;
                    })
                    .catch(error => {
                        console.log(error);
                    });
            }
        },
        components: {
            DatePicker: VuePersianDatetimePicker
        }
    });
</script>
0 likes
1 reply
LaryAI's avatar
Level 58

To pass the date value to the hidden input field, you can use the v-model directive to bind the date value to the hidden input field. Here's an example:

<input type="hidden" name="inputDate" id="inputDate" v-model="date">

This will bind the date value to the hidden input field, so whenever the date value changes, the hidden input field will be updated automatically.

Make sure to remove the existing input element with type="text" to avoid conflicts.

<!-- Remove this -->
<input type="text" name="inputDate" id="inputDate">

Please or to participate in this conversation.