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
  • TallFormComponent vs Headless vs TallFormFields
  • Markup for Headless and TallFormFields
  • Important! ::blade not ::make
  • Styling

Was this helpful?

  1. Create Forms
  2. Form Types

Headless

PreviousFields onlyNextForm attributes

Last updated 3 years ago

Was this helpful?

Sometimes you only want the fields instead of an entire form component. When you use the fields this way, you design the component following Livewire conventions.

Think of it as a tool to auto-generate html for the fields, nothing else.

TallFormComponent vs Headless vs TallFormFields

(Standard form type)

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

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

(Fields only, form type)

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',
    ];
 }

Markup for Headless and TallFormFields

Important! ::blade not ::make

  • You cannot use fields that lack "headless" support, like the Repeater.

  • Check the "Headless" tab on each field page, you might need to add traits.

  • You will not be able to use field methods like rules() or default()

  • Above, Below, Before, After, Help slots are available.

  • Validation errors are automatically displayed

Styling

"Headless" is usually used to refer to something without styling. With Tall-forms this is true in the sense that you control the styling in the theme file.

But, you can override the fields default styling when you declare the field in a blade view, which is why we can call it "headless" :)

See Blade components, page

See page about differences

All fields are blade components. There are aliases in the file.

standard
"Label wrapper"
Field Declaration
config