Expose group of fields as a new single reusable field
Hi there!
First of all thank you for this amazing framework!
I'm looking to build a reusable from input/component. It's a text input and a select. Ideally I'd provide this field as a new component that exposes a single value to the form state.
I see two ways of making this work:
1. Build a group/component that has it's own schema of
Input
and Select
.
Is there a go-to way of doing this? Ideally I can reuse the existing Input
and Select
like in the example above.
Is there a way of exposing a single named property to the form state?
2. Build a view component and write the input/select myself.
Downside is that you would have to implement the inputs and selects and can't really reuse the existing filament input components.6 Replies
you're nearly there
extend
Group
, override the setUp() method
then call parent::setUp()
, then $this->schema()
you dont need to override make()Makes sense! And what about
Is there a way of exposing a single named property to the form state?
ah so it should be JSON?
yes that is possible
essentially it is
->statePath('nameoffield')
if you want a better DX than having to use that... then maybe extend Component instead of Group, make a new make() method which accepts the state path, pass that state path to the constructor, call schema() and statePath() in the constructor to set the state path. then you dont need setUp() either
then also check the $view of the Group component and copy that $view to your new componentHmm yes so for example i have this form
which would ideally result in
or
I know the latter is possible with
statePath
now but would like to know if option one is also possible (and recommend). Maybe using the hydrate...
methods?the problem is not the saving, its the loading again
you then have to extract the currency from the formatted string
and not all currencies have their symbols at the start
json or 2 separate columns is your best bet here
👌
Thanks mate!