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
  • Requirements
  • Autogenerated or Headless

Was this helpful?

TALL-forms

Autogenerated and Headless Livewire form components

NextInstallation

Last updated 3 years ago

Was this helpful?

This is the documentation for Tall-forms v8

Requirements

  • Php ^8.0|^8.1

  • Laravel ^8.75.0

  • Livewire ^2.8.1

  • Alpine ^3.5.1

  • Tailwind 2.x or 3.x

Autogenerated or Headless

(Extend TallFormComponent)

In a TallFormComponent. You don't need to add properties, render(), $rules or create a blade view.

<?php

namespace App\Http\Livewire\Forms;

use App\Models\Post;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\Textarea;
use Tanthammar\TallForms\TallFormComponent;

class PostForm extends TallFormComponent
{

    public function mount(Post $post): void
    {
        $this->mount_form($post);
    }

    protected function fields(): array
    {
        return [
            Input::make('Title')->rules('required|string|min:6'),
            Textarea::make('Content')->rules('required|string|max:500')
        ];
    }
}

No view needed

(Extend TallFormInModal)

Same as the Autogenerated form, but opens in a modal

namespace App\Http\Livewire\Forms;

use App\Models\Post;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\Textarea;
use Tanthammar\TallForms\TallFormInModal;

class PostModalForm extends TallFormInModal
{
     /*
     * button color presets:
     * white, indigo, blue, green, yellow, red, gray, orange, teal, info, success, danger, warning, primary, secondary
     public string $closeBtnColor = 'white';
     public string $submitBtnColor = 'primary';

     * Methods to override
     public function loadModal(int|string $modelKey): void
     public function closeModal(): void
     public function modalSubmit(): void
     */
    
    public function mount()
    {
        $this->mount_form(new Post);
    }

    protected function formAttr(): array
    {
        return [
           'formTitle' => 'Post form',
           'formSubtitle' => 'Form Subtitle slot',
           'modalMaxWidth' => 'xl', //default = 'lg', options: sm, md, lg, xl, 2xl
       ];
    }
    
    protected function fields(): array
    {
        return [
            Input::make('Title')->rules('required|string|min:6'),
            Textarea::make('Content')->rules('required|string|max:500'),
        ];
    }
}

Add a button to any blade view

<button type="button"
    wire:click="$emitTo('forms.post-modal-form', 'openModal', User::first()->id)"
>New Post</button>

Add the modal form component to your app layout

<livewire:forms.post-modal-form />

(Extend native Livewire Component)

When you want to create your own blade view and design the component, following Livewire conventions.

You don't have to use an Eloquent Model instance, this is just an example.

<?php

namespace App\Http\Livewire\Forms;

use App\Models\Post;
use Livewire\Component;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\Textarea;

class PostForm extends Component
{
    public Post $post;
    
    protected $rules = [
        'post.title' => 'required|string|min:6',
        'post.content' => 'required|string|max:500',
    ];

    public function save()
    {
        $this->validate();
        $this->post->save();
    }

    public function render()
    {
        return view('livewire.post-form');
    }

}

Declare the fields in the blade view

resources/views/livewire/post-form.blade.php

<form wire:submit.prevent="save">
    
    <x-tall-input :field="Input::blade('Title' 'post.title')" />
    <x-tall-textarea :field="Textarea::blade('Content' 'post.content')" />
    
    <button type="submit">Save</button>
    
</form>

Wrapping fields with labels

(Extend TallFormFields)

This form type is almost the same as Headless. The difference is that you declare the fields in the Livewire Component instead of the blade view.

Make a Livewire component that extends TallFormFields and design the component, following Livewire conventions.

You don't have to use an Eloquent Model instance, this is just an example.

<?php

namespace App\Http\Livewire\Forms;

use App\Models\Post;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\Textarea;
use Tanthammar\TallForms\TallFormFields;

class PostForm extends TallFormFields
{
    public Post $post;
    
    protected $rules = [
        'post.title' => 'required|string|min:6',
        'post.content' => 'required|string|max:500',
    ];
    
    protected function fields(): array
    {
        return [
            Input::blade('Title', 'post.title'),
            Textarea::blade('Content', 'post.content'),
        ];
    }

    public function save()
    {
        $this->validate();
        $this->post->save();
    }

    public function render()
    {
        return view('livewire.post-form');
    }

}

@include('tall-forms::fields-only')

When you extend TallFormsFields , the form view must contain the blade directive that renders the form fields:

resources/views/livewire/post-form.blade.php

<form wire:submit.prevent="save">
    
    @include('tall-forms::fields-only')
    
    <button type="submit">Save</button>
    
</form>

TallFormFields properties

The TallFormFields component only contains minimum functionality to render the fields and it uses the "Headless" way to generate field html.

There are only a few properties in TallFormFields that you can override with the formAttr() method.

protected function formAttr(): array
 {
     return [
        'inline' => true, //stacked or inline layout
        'inlineLabelAlignment' => 'tf-inline-label-alignment',
        'labelW' => 'tf-label-width',
        'fieldW' => 'tf-field-width',
    ];
 }

See Blade components, page

Alpine Focus plugin ->
Alpine Collapse plugin ->
standard
"Label wrapper"