Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 8fd36b1

Browse files
committed
Update README.md
1 parent d7c1f79 commit 8fd36b1

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ composer require protonemedia/laravel-form-components
3434

3535
todo
3636

37-
## Usage
37+
## Quick example
3838

3939
```blade
4040
<x-form>
@@ -60,6 +60,82 @@ todo
6060
</x-form>
6161
```
6262

63+
## Usage
64+
65+
### Input and textarea elements
66+
67+
The minimum requirement for an `input` or `textarea` is a `name` attribute.
68+
69+
```blade
70+
<x-form-input name="company_name" />
71+
```
72+
73+
Optionally you can add a `label` attribute, which can be computed as well.
74+
75+
```blade
76+
<x-form-input name="company_name" label="Company name" />
77+
<x-form-input name="company_name" :label="trans('forms.company_name')" />
78+
```
79+
80+
You can also choose to use a `placeholder` instead of a label, and of course you can change the `type` of the element.
81+
82+
```blade
83+
<x-form-input type="email" name="current_email" placeholder="Current email address" />
84+
```
85+
86+
By default every element shows validation errors but you can hide them if you want.
87+
88+
```blade
89+
<x-form-textarea name="description" :show-errors="false" />
90+
```
91+
92+
### Default value
93+
94+
You can use the `default` attribute to specify the default value of the element.
95+
96+
```blade
97+
<x-form-textarea name="motivation" default="I want to use this package because..." />
98+
```
99+
100+
### Binding a target
101+
102+
Instead of setting a default value, you can also pass in a target, like an Eloquent model. Now the component will get the value from the target by the `name`.
103+
104+
```blade
105+
<x-form-textarea name="description" :bind="$video" />
106+
```
107+
108+
In the example above, where `$video` is an Eloquent model, the default value will be `$video->description`.
109+
110+
### Binding a target to multiple elements
111+
112+
You can also bind a target by using the `@bind` directive. This will bind the target to all elements until the `@endbind` directive.
113+
114+
```blade
115+
<x-form>
116+
@bind($video)
117+
<x-form-input name="title" label="Title" />
118+
<x-form-textarea name="description" label="Description" />
119+
@endbind
120+
</x-form>
121+
```
122+
123+
You can even mix targets!
124+
125+
```blade
126+
<x-form>
127+
@bind($user)
128+
<x-form-input name="full_name" label="Full name" />
129+
130+
@bind($userProfile)
131+
<x-form-textarea name="biography" label="Biography" />
132+
@endbind
133+
134+
<x-form-input name="email" label="Email address" />
135+
@endbind
136+
</x-form>
137+
```
138+
63139
### Testing
64140

65141
``` bash

0 commit comments

Comments
 (0)