Lifecycle hooks
Apart from Livewire defaults, TALL-forms offers these additional hooks.
Hooks
Description
updatedFoo($value, $fieldIndexKey)
after field update,
before real-time validation
updatedFooValidate()
after field update,
after updatedFoo()
,
replaces real-time validation
saveFoo($validated_value)
After form submit,
onCreateModel($validated_data)
On form submit,
if $model
does not exist.
onUpdateModel($validated_data)
On form submit,
if $model
does exist.
onDeleteModel()
When the delete button is clicked.
There is a $this->defaultDelete()
method you can call after performing your access control.
saveAndStayResponse()
Save/Submit button
saveAndGoBackResponse()
Save and go back button
updatedFoo
Executes BEFORE field validation and AFTER field value is updated
The default Livewire way to manipulate data when a field is updated is to add an updatedFieldName()
method to your component. This is not working with the form-component because the field is accessed via the field_data
. To get around it, this package has added a fix.
You do NOT have to prefix with FormData
Example method name for an array field
form_data.people.name
will becomeupdatedPeopleName($validated_value)
Example method name for
form_data.some_field_name
will becomeupdatedSomeFieldName($validated_value)
Example from above, the form_data.price
field would become
saveFoo($validated_value)
See the Manually saving data page
onCreateModel($validated_data)
Required method if you are creating a new model instance
Executes AFTER field validation, intended to CREATE a model
The
$validated_data
contains all fields exceptcustom
fields andrelational
fields
onUpdateModel($validated_data)
Optional method, the
TallForm
trait has a default methodExecutes AFTER field validation, intended to UPDATE an existing model
The
$validated_data
contains all fields exceptcustom
fields andrelational
fields
This is the default method supplied by the TallForm
trait
onUpdateModel vs onCreateModel
When a form is submitted, the TallForm traits calls one of these methods based on
$model->exists
onCreateModel()
is mandatory, in a form where the model doesn't exist when the form mounts vsonUpdateModel()
, which is optional.
This is how the form component evaluates which method to call.
onDeleteModel
Optional method, the
TallForm
trait has a default methodExecutes when clicking the forms Delete button Set component property
$showDelete
to true, to show the delete button.The hook is invoked if model exists
This is the default method supplied by the TallForm
trait
The bundled defaultDelete() method
saveAndStayResponse
This method defines the response after successful submission via the Save/Submit
button. By default it stays on the same page and notifies a message or errors.
Example on how to override it.
saveAndGoBackResponse
This method defines the response after successful submission via the Save & Go Back
button.
By default it returns redirect()->back()
.
Example on how to override the method:
Last updated
Was this helpful?