Custom field

If you make a custom field. Please share it with the community! (Make a PR)

Forget the label, help and error messages.

Don't create code for labels, help or error messages when creating a custom field, it's automatically added by the form component.

Extend existing component, instead of creating a custom field

If you are looking to change the styling of an existing field it is enough to extend the fields Blade Class or create your own theme.

Steps to create a custom field

1. Create a Field class that extends BaseField

  • Name your class in a non-conflicting and descriptive way

  • add the $type property, best practice is to slug case the class name.

namespace YourNameSpace;

use Tanthammar\TallForm\BaseField;

class MyField extends BaseField
{
    public $specialProp; //example adding your own properties

    // all properties that exists in BaseField or its traits should be set in the overrides() method.
    public function overrides(): self
    {
       $this->type = 'my-field'; //required property!
       return $this;
    }

    //now your field has access to all BaseField methods, you can override them or add your own
    public function specialProp($prop): self
    {
        $this->specialProp = $prop;
        return $this;
    }
}

2. Create a Blade component class, with the same name

Extend BaseBladeField

3. Create a blade component view

  • resources/views/components/my-field.blade.php.

  • Name the view the same as the field $type.

  • You have access to all the $field attributes and methods, in your blade view.

Example using an input field based on MyField blade component class:

4. Use your field in a form component

Please share your field!

If you make a new field. Please share it! Make a PR or paste the code in an issue, and I'll add it to the package.

Last updated

Was this helpful?