protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 110 forks source link

value assigned to x-splade-input from x-splade-script gets ignored as form saved. #499

Closed samk1r0 closed 6 months ago

samk1r0 commented 1 year ago

I'm assigning a value to x-splade-input element in x-splade-script. The problem appears as I save the form, at this moment data get's updated with the initial value. However If i change the input manually(by clicking on the input field and modifying value) it doesn't set the value to the inital value.

pascalbaljet commented 1 year ago

Please share your script.

samk1r0 commented 1 year ago
<section>
    <x-splade-form method="patch" :action="route('widget.update')" :default="$user" preserve-scroll>
        <x-splade-input id="duration" name="duration"></x-splade-input>
        <div>
            <x-splade-submit :label="__('Save')" />
        </div>
    </x-splade-form>
</section>
<x-splade-script>   
    document.addEventListener('DOMContentLoaded', ()=>{
        let alertDuration = document.getElementById('duration');
        alertDuration.value = 123;
    })
</x-splade-script>
samk1r0 commented 1 year ago

@pascalbaljet So do you know what's the reason for this problem?

romain-lgr commented 1 year ago

@samk1r0 duration should be a field of your User model and then predefined. Your code is quite strange, not sure what you want to achieve.

samk1r0 commented 1 year ago

@romain-lgr but what if I don't have duration column in my users table and I only want to use this field for calculation purposes? Also, what you find strange in my code?

jadetulda1996 commented 11 months ago

@romain-lgr but what if I don't have duration column in my users table and I only want to use this field for calculation purposes? Also, what you find strange in my code?

After the alertDuration.value = 123; line, write the ff. alertDuration.dispatchEvent(new Event('input'))

PS: I can't reference the link, I forgot where did I got the idea xx)

samk1r0 commented 11 months ago

@romain-lgr but what if I don't have duration column in my users table and I only want to use this field for calculation purposes? Also, what you find strange in my code?

After the alertDuration.value = 123; line, write the ff. alertDuration.dispatchEvent(new Event('input'))

PS: I can't reference the link, I forgot where did I got the idea xx)

what's ff?

jadetulda1996 commented 11 months ago

@romain-lgr but what if I don't have duration column in my users table and I only want to use this field for calculation purposes? Also, what you find strange in my code?

After the alertDuration.value = 123; line, write the ff. alertDuration.dispatchEvent(new Event('input')) PS: I can't reference the link, I forgot where did I got the idea xx)

what's ff?

only means "following"..

"write the following"