F
Filament3mo ago
pritam

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 ?
No description
22 Replies
pritam
pritam3mo ago
hey anyone ?
krekas
krekas3mo ago
value is null. error cannot be clearer
pritam
pritam3mo ago
I am updating the value with javascirpt with a script that load on every page
krekas
krekas3mo ago
Then your Javascript code is bad and doesn't set the value
ericmp
ericmp3mo ago
can u share the form schema?
pritam
pritam3mo ago
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
pritam
pritam3mo ago
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
ericmp
ericmp3mo ago
try make the input live, maybe works ->live() not sure though
pritam
pritam3mo ago
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
ericmp
ericmp3mo ago
but how r u trying to update it with js? $wire... or how?
pritam
pritam3mo ago
vanilla js do we have any other way by which we can update the field value ?
ericmp
ericmp3mo ago
share the js script please, but only the specific part
pritam
pritam3mo ago
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
ericmp
ericmp3mo ago
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
pritam
pritam3mo ago
okay thank you I will follow the docs
ericmp
ericmp3mo ago
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
pritam
pritam3mo ago
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
ericmp
ericmp3mo ago
hmmm for me this makes no sense i mean, not for u for ur boss
pritam
pritam3mo ago
okay, i even don't know why he wants it this way
ericmp
ericmp3mo ago
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
pritam
pritam3mo ago
thank you for helping. I will see if he gets convinced