> For the complete documentation index, see [llms.txt](https://tina-hammar.gitbook.io/tall-forms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tina-hammar.gitbook.io/tall-forms/field/alpine.md).

# Custom field attributes

Some custom fields does not have these methods, like `SpatieTags`, `FileUpload` and `Trix`, as it could break their functionality.

```php
//Field attribute methods and which config value they correspond to
rootAttr(array $attributes, bool $mergeClasses = true) //field-attribute['root']
beforeAttr(array $attributes, bool $mergeClasses = true) //field-attribute['before']
beforeTextAttr(array $attributes, bool $mergeClasses = true) //field-attribute['before-text']
aboveAttr(array $attributes, bool $mergeClasses = true) //field-attribute['above']
belowAttr(array $attributes, bool $mergeClasses = true) //field-attribute['below']
belowWrapperAttr(array $attributes, bool $mergeClasses = true) //field-attribute['below-wrapper']
afterTextAttr(array $attributes, bool $mergeClasses = true) //field-attribute['after-text']
afterLabelAttr(array $attributes, bool $mergeClasses = true) //field-attribute['after-label']

//custom input attribute
inputAttr(array $attributes) //no value in config
```

### inputAttr(array $attributes)

* **Do NOT set** any `wire:model...`, use the field `->wire()` method instead. Otherwise, it will be applied twice.
* Overrides the `field-attribute['input']` in the config file

### Merge with config, example

```
Input::make('Name')->labelAttr('bg-green-300') //merge with config
Input::make('Name')->labelAttr('bg-green-300', false) //replace config
```

### Alpine Js example

This is a somewhat ridiculous example just to show the power you have with the `inputAttr()`. \
In this example Livewire sets the initial value to `3`, then Alpine sets it to `2`, and finally Alpine sets it to `10`, when the component has finished mounting.

```php
Input::make('Integer')
    ->custom()//see Manually saving data
    ->type('number')->step(1)->min(1)->max(100)
    ->default(3)
    ->wire('wire:model.defer')//Livewire will not care about this field until form is submitted
    ->inputAttr([
        'x-data' => "{ count: 2 }",
        'x-model' => "count",
        'x-init' => "() => { count = 10 }",
        'class' => "form-input bg-green-500" //replaces any value from config file
    ]),
```

### Input pattern format, example

```php
Input::make('Phone')
    ->type('tel')
    ->prefix('phone:')
    ->above('Example input with inputAttr() maxlength and size')
    ->inputAttr([
        'pattern' => "[0-9]{12}",
        'maxlength' => 12
    ])
    ->placeholder('### ### ### ###')
    ->rules('required')
    
//Do not forget to add a pseudo class, input:invalid { border: red solid 3px; } or similar to your app.css.
//If you want to take full advantage of the html5 pattern attribute
```

### Another Alpine Js example

* You can use the methods mentioned on the [Styling](https://github.com/tanthammar/tall-forms/wiki/BaseField-Styling) page to set attributes on other elements.
* See another example on the [Form Slots](https://github.com/tanthammar/tall-forms/wiki/Form-Slots) page.

```
Input::make('Name')
    ->rootAttr([
       'x-data' => "{ foo: 'bar'}",
       'class' => 'border rounded',
    ])
    ->inputAttr([
        'x-init' => "foo = 'baz'"
    ])
    ->required(),
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tina-hammar.gitbook.io/tall-forms/field/alpine.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
