TALL-forms
  • TALL-forms
  • Installation
    • Quickstart: Artisan cmd
    • Manual installation
      • Package
      • Translations
      • Css & Theme
      • Javascript
      • Tailwind
      • Laravel Mix
      • Wrapper view
      • Laravel Jetstream/Breeze
  • Upgrade v7 to v8
    • Configuration changes
    • Component & Field changes
    • Blade view changes
    • Notification changes
    • Styling changes
  • Concept
    • Configuration
    • Validation
    • Styling
    • Icons
    • Javascript
    • Layout vs Wrapper
    • Model binding
    • Manually saving data
    • Extend Blade Components
  • Create Forms
    • Form Data
    • Form Types
      • Standard form
      • As modal
      • Without buttons
      • Fields only
      • Headless
    • Form attributes
    • Form buttons
    • Form slots
    • Form methods
    • Lifecycle hooks
    • Render a form
    • Mass generate
  • Fields
    • Declaration
    • Labels
    • Field Slots
    • Field methods
    • Custom field attributes
    • Conditional field
    • Custom view
    • Custom field
    • Custom Livewire component
    • Relations
    • Fields
      • Checkbox
      • Checkboxes
      • FileUpload
      • Honeypot
      • ImageCropper
      • Input
      • Password
      • InputArray
      • KeyVal (array)
      • Radio
      • Range
      • Repeater (array)
      • Search
      • Select & Multiselect
      • Tags
      • TagsSearch
      • Textarea
      • Trix
      • SpatieTags
    • Sponsor Fields
      • More Inputs
      • CKEditor
      • DatePicker
      • Heading
      • Markdown
      • Panels
      • SearchList
      • SelectOptGroup
      • Tabs
      • Trix, file-uploads
  • Blade components
    • Notifications
    • Label wrapper
    • Button
    • Modal blade component
    • Modal form blade component
  • Examples
    • Input examples
    • Array fields example
Powered by GitBook
On this page
  • updatedFoo
  • saveFoo($validated_value)
  • onCreateModel($validated_data)
  • onUpdateModel($validated_data)
  • onUpdateModel vs onCreateModel
  • onDeleteModel
  • saveAndStayResponse
  • saveAndGoBackResponse

Was this helpful?

  1. Create Forms

Lifecycle hooks

PreviousForm methodsNextRender a form

Last updated 3 years ago

Was this helpful?

Apart from Livewire , 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 become updatedPeopleName($validated_value)

  • Example method name for form_data.some_field_name will become updatedSomeFieldName($validated_value)

Example from above, the form_data.price field would become

public function updatedPrice($validated_value)
{
    $this->form_data['price'] = round($validated_value, 2);
}

saveFoo($validated_value)

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 except custom fields and relational fields

public function onCreateModel($validated_data)
{
    $this->model = User::create($validated_data);
}

onUpdateModel($validated_data)

  • Optional method, the TallForm trait has a default method

  • Executes AFTER field validation, intended to UPDATE an existing model

  • The $validated_data contains all fields except custom fields and relational fields

This is the default method supplied by the TallForm trait

public function onUpdateModel($validated_data)
{
    $this->model->update($validated_data);
}

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 vs onUpdateModel(), which is optional.

This is how the form component evaluates which method to call.

    filled($this->model) && $this->model->exists ? $this->onUpdateModel($model_fields_data) : $this->onCreateModel($model_fields_data);

onDeleteModel

  • Optional method, the TallForm trait has a default method

  • Executes 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

protected function onDeleteModel()
{
    $this->defaultDelete();
}

The bundled defaultDelete() method

protected function defaultDelete()
{
    $className = is_object($this->model) ? get_class($this->model) : "item";
    $this->model->delete();
    session()->flash('success', "The {$className} was deleted");
    return redirect(urldecode($this->previous));
}

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.

protected function saveAndStayResponse()
{
    $this->notify('success');
    return redirect()->route('users.edit', $this->model->id);
}

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:

protected function saveAndGoBackResponse()
{
    return redirect()->route('users.index');
}

after validation To manually save form data See

See the data page

defaults
Manually saving
Manually saving data