protonemedia/laravel-splade

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

Closed this issue · 8 comments

  • Laravel Version: 10.18.0
  • PHP Version: 8.1.11
  • Splade JS Version (npm): 1.4.16
  • Splade PHP Version (composer): 1.4.16
  • Dev environment (OS, Sail/Valet/etc): Windows

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.

Please share your script.

<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>

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

@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.

@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?

@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)

@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?

@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"