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
  • Mandatory methods
  • mount_form
  • fields
  • Optional methods
  • formAttr
  • beforeFormProperties
  • afterFormProperties
  • resetFormData = Reset button
  • render
  • autoSelectSingleArrayValue

Was this helpful?

  1. Create Forms

Form methods

PreviousForm slotsNextLifecycle hooks

Last updated 3 years ago

Was this helpful?

protected function mount_form($model): void //see model binding page
protected function formAttr(): array
protected function beforeFormProperties(): void
protected function afterFormProperties(): void
protected function fields(): array
public function resetFormData(): void //reset button
public function render()
protected function autoSelectSingleArrayValue(string $arrayName, string $field): void
// also see Lifecycle Hooks, page

Mandatory methods

mount_form

If the form type requires it, pass a $model instance to the form in mount() See page.

fields

Where you define the form fields.

protected function fields()
    {
        return [
            Input::make('Name')->rules('required'),
        ];
    }

Optional methods

formAttr

protected function formAttr(): array
{
    return [
        'formTitle' => 'Create User',
    ];
}

beforeFormProperties

Executes before form_data is set. Example:

protected function beforeFormProperties()
{
    $condition = true;
    if (!$condition) {
      session()->flash('negative', 'The condition is required!');
      return redirect(route('some_route'));
    } else {
        $this->model->some_prop = true;
    }
}

afterFormProperties

protected function afterFormProperties() {
    $this->form_data['someField'] = //change the value of the populated form data
}

resetFormData = Reset button

If you want to override the default reset form method. You can call this method to reset the form, in any another method

$this->resetFormData();

Default:

public function resetFormData()
{
    $this->resetErrorBag();
    $this->setFormProperties();
}

render

This method renders the form component view, you don't need to add it to the component. If you have to override it, make sure to return $this->formView().

Example:

public function render()
{
    // my custom code
    
    return $this->formView();
}

autoSelectSingleArrayValue

Auto populate a field with an option if there is only one value available. Initially developed for BelongsTo relationships where a query might return only one model, but can be used for any field as a conditional value.

  • $arrayName = Flat array as key => value. IMPORTANT: Please note that the method only works with a key/value array. It extracts the value, with php array_values(), and uses it to populate the field.

  • $field = String. The name of the field that should be auto populated.

  • IMPORTANT NOTE: This method can only be called after form_data is set, like in the afterFormProperties() method.

Example: If there is only one item in the users array, the user_id field will be auto populated.

public $users;

public function mount()
{
    //Pretend this query only returns one model
    $this->users = Users::query()->someScope()->select('id', 'name')->get()->pluck('id', 'name')->all();
}

public function afterFormProperties() // the method can only be used after form_data is generated
{
    // just pass the attribute name 'users', not $this->users
    $this->autoSelectSingleArrayValue('users', 'user_id');
}

protected function fields()
{
    return [
        Select::make('Author', 'user_id')->options($this->users),
    ];
}

Form defaults reside in file, override them with the formAttr() method. See or for more examples.

Executes after form_data is set. See another example at the .

Model Binding
tall-form config
Form Buttons
Form slots
end of this page