F
Filament3mo ago
giro

Get data from custom form field

From my custom form field how can get data from another field. I try $get but not working
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;
use Filament\Forms\Get;

class TotalProducts extends Field
{
protected string $view = 'forms.components.total-products';

public function getData()
{
dd($get('blueprint.oferta_comercial.productes'));
}
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;
use Filament\Forms\Get;

class TotalProducts extends Field
{
protected string $view = 'forms.components.total-products';

public function getData()
{
dd($get('blueprint.oferta_comercial.productes'));
}
}
8 Replies
alek
alek3mo ago
From what I understand, $get is meant to be used in the form or table action, not in the component itself. Try using the state or form call here instead to dig for what you need. Can't test this right now but play around with: $myState = $this->getState(); // This state $myForm = $this->getForm(); $value =$myForm->getState('blueprint.oferta_comercial.productes'); dd($myState, $value);
giro
giroOP3mo ago
Not working, strange $this->getState(); return null on this field
alek
alek3mo ago
What about $myForm->getState() is this returning anything?
LeandroFerreira
LeandroFerreira3mo ago
are you trying to get the data in the view file like this?
<div>
Total: {{ $getGetCallback()('blueprint.oferta_comercial.productes') }}
</div>
<div>
Total: {{ $getGetCallback()('blueprint.oferta_comercial.productes') }}
</div>
giro
giroOP3mo ago
GetForm function no exist Great, this work
zydnrbrn
zydnrbrn3mo ago
How can i see detailed docs about this method or related method like this sir?
LeandroFerreira
LeandroFerreira3mo ago
I don't think that it is documented, but you can check it in the php api doc
zydnrbrn
zydnrbrn3mo ago
thanks sirr i need thissss

Did you find this page helpful?