Filament
I am updating the total_amount field with javascript.
The total amount field is made using filament but when I submit the value. It is not getting updated in the database
What could be the reason ?
22 Replies
hey anyone ?
value is null. error cannot be clearer
I am updating the value with javascirpt
with a script that load on every page
Then your Javascript code is bad and doesn't set the value
can u share the form schema?
yeah sure
On entering field manually I am able to store the value in the database but with javascript when i update the input field it is not getting updated
On entering field manually I am able to store the value in the database but with javascript when i update the input field it is not getting updated
try make the input live, maybe works
->live()
not sure though
tried but not working
to set a value we have set method in filament I think we need to replicate the same method with javascript
maybe it will work
but how r u trying to update it with js? $wire... or how?
vanilla js
do we have any other way by which we can update the field value ?
share the js script please, but only the specific part
sure
function calculateTotal(){
let total = 0;
let inputFields = document.querySelectorAll('.filament-table-repeater-tbody-cell .fi-fo-field-wrp .fi-input');
inputFields.forEach(element => {
if(element.value != ""){ total += parseFloat(element.value); } }) const totalContributionField = document.querySelector('input[id="data.total_amount"]'); totalContributionField.value = total; } I am updating totalContributionField
if(element.value != ""){ total += parseFloat(element.value); } }) const totalContributionField = document.querySelector('input[id="data.total_amount"]'); totalContributionField.value = total; } I am updating totalContributionField
u gotta get deeper
filament uses livewire.
livewire uses alpinejs
u should learn how to interact with livewire & alpinejs via js to achieve that
https://livewire.laravel.com/docs/javascript
okay thank you
I will follow the docs
btw not sure why u need to calculate the total like that but u may need it. else, u could do it on the livewire component itself. not sure if i explain myself
My boss wants to use client side code to calculate the total
I did it with live() and afterUpdate function but he said to use client side code
So I want using javascript for that purpose
@ericmp
hmmm
for me this makes no sense
i mean, not for u
for ur boss
okay, i even don't know why he wants it this way
if i were u id try to tell ur boss that executing code on the frontend is okay, but it may be cases where is not needed
and this code - https://discord.com/channels/883083792112300104/1233357098385932369/1233405662252372091 - doesnt seem to stress the server at all, i wouldnt worry about it
i would worry to follow conventions, workflows, good practices, and keeping a mantainable code
cuz if u start doing this, ull end up with a code that will prolly be hard to follow
but up to u, this is just what id do
thank you for helping. I will see if he gets convinced