w5m
"data." prefix on greater than form validation message
Not sure if I'm missing something obvious here, but I'm wanting to make sure one form field is greater than 4 * value of another field.
I've achieved this by passing a closure to the
->gt()
method...
...but the resulting validation message is preceded by a data.
prefix...
Is there a way to remove this prefix without creating my own custom rules?1 replies
Pass form data (`$state`) to `ChartWidget` in resource Create page
I have embedded a
ChartWidget
in a resource Create page (of type CreateRecord
) via the getFooterWidgets()
method.
Is there a way for the ChartWidget
to access the data in the form fields (e.g. via a $state
variable or similar) before the form is submitted (i.e. there is no record in the database table yet)?
What I'm trying to do is populate a chart after clicking a "Calculate" button (i.e. Action
) on the form and would appreciate any thoughts as to how to approach this.
Many thanks.9 replies
Custom "Save" button to create or save a form
I'm trying to add a custom "Save" button (i.e. action) to a form.
If I pass the string
'save'
to the ->action()
method, it successfully saves changes to any form fields if I'm Editing a record and click the "Save" button. However, if I'm Creating a record and click the "Save" button, I see an error: Unable to call component method. Public method [save] not found on component
.
If I pass the string 'create'
to the ->action()
method, it successfully saves the values in the form fields if I'm Creating a record and click the "Save" button. However, if I'm Editing a record and click the "Save" button, I see an error: Unable to call component method. Public method [create] not found on component
.
I tried passing a closure to the ->action()
method to return the appropriate string depending on the type of form, but this causes nothing to happen on clicking the "Save" button...
->action(fn ($operation) => ($operation === 'edit') ? 'save' : 'create')
I'm guessing that ultimately my closure needs to return an object, rather than a string, but I'm not clear what that object should be.
Any pointers would be gratefully received.6 replies
Setting model attribute based on form field value
If I create a private
my_people_count
variable in my Example
model and a peopleCount()
method (return type of Attribute
) which gets & sets the private variable. If I also include in my ExampleResource
class the following form component: TextInput::make('people_count'),
...what else do I need to do to cause Filament to call the attribute setter when processing the submitted form? (I forgot to point out that the count will not be saved to the underlying database table - it will only be used to indicate how many related model instances to create)2 replies
Sortable TextColumn based on Enum labels rather than query
I'm currently using a
TaskStatus
enum which implements the HasLabel
contract. In this enum I've defined an orderedLabels()
method to return an array of enum cases ordered by the corresponding labels.
I've successfully utilised the enum in a form and in a table...
TextColumn::make('task_status_id')
->label('Status')
->sortable()
->badge(),
What I would ideally like to do is pass something into the sortable()
method of the TextColumn
which allows me to specify how to order the enum (as it currently orders by the task_status_id
DB table field, an integer, which corresponds to an int-backed enum case).
Other than backing the enum cases with integers which match alphabetical order, is there a way I could specify that sorting for this column should be done in alphabetical order of enum labels rather than via a query?1 replies