Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit b6cf458

Browse files
J87NLpascalbaljet
andauthored
Formbuilder (#324)
Co-authored-by: Pascal Baljet <pascal@pascalbaljet.nl>
1 parent 0c9a5d3 commit b6cf458

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2889
-50
lines changed

app/app/Forms/ExampleForm.php

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
<?php
2+
3+
namespace App\Forms;
4+
5+
use ProtoneMedia\Splade\AbstractForm;
6+
use ProtoneMedia\Splade\FormBuilder\Checkbox;
7+
use ProtoneMedia\Splade\FormBuilder\Color;
8+
use ProtoneMedia\Splade\FormBuilder\Date;
9+
use ProtoneMedia\Splade\FormBuilder\Email;
10+
use ProtoneMedia\Splade\FormBuilder\Hidden;
11+
use ProtoneMedia\Splade\FormBuilder\Input;
12+
use ProtoneMedia\Splade\FormBuilder\Number;
13+
use ProtoneMedia\Splade\FormBuilder\Password;
14+
use ProtoneMedia\Splade\FormBuilder\Radio;
15+
use ProtoneMedia\Splade\FormBuilder\Select;
16+
use ProtoneMedia\Splade\FormBuilder\Submit;
17+
use ProtoneMedia\Splade\FormBuilder\Text;
18+
use ProtoneMedia\Splade\FormBuilder\Textarea;
19+
use ProtoneMedia\Splade\FormBuilder\Time;
20+
use ProtoneMedia\Splade\SpladeForm;
21+
22+
class ExampleForm extends AbstractForm
23+
{
24+
public function configure(SpladeForm $form)
25+
{
26+
$form
27+
->action(route('formbuilder.fromClass.store'))
28+
->id('exampleform')
29+
->fill([
30+
'hiddenInput1' => 'Test value hidden input 1',
31+
'hiddenInput2' => 'Test value hidden input 2',
32+
'inputText1' => 'Test value input text field 1',
33+
'disabledTextField' => 'This field is disabled',
34+
'readonlyTextField' => 'This field is readonly',
35+
'disabledAndReadonlyTextField' => 'This field is disabled and readonly',
36+
'colorInput' => '#cccccc',
37+
]);
38+
}
39+
40+
public function fields(): array
41+
{
42+
return [
43+
Hidden::make('hiddenInput1')
44+
->label('Hidden field using Hidden::make()'),
45+
46+
Input::make('hiddenInput2')
47+
->label('Hidden Input using ->hidden()')
48+
->hidden(),
49+
50+
Input::make('inputText1')
51+
->label('Standard input text field')
52+
->help('Test help 1')
53+
->rules('required'),
54+
55+
Input::make('inputText2')
56+
->label('Input text field (minlength: 2, maxlength: 255)')
57+
->placeholder('Placeholder...')
58+
->minLength(2)
59+
->maxLength(255)
60+
->attributes(['data-custom' => 123])
61+
->rules('required|max:255'),
62+
63+
Input::make('inputText3')
64+
->label('Input text field with fixed length(6)')
65+
->length(6)
66+
->prepend('Test prepend'),
67+
68+
Number::make('inputNumber')
69+
->label('Input number field (min 1, max 100)')
70+
->numeric()
71+
->minValue(1)
72+
->maxValue(100)
73+
->append('Test append'),
74+
75+
Number::make('testNumberInput')
76+
->label('Or as Number-alias field')
77+
->prepend('Test prepend')
78+
->append('Test append'),
79+
80+
Number::make('testNumberInput2')
81+
->label('Number field with ->unsigned()')
82+
->unsigned(),
83+
84+
Number::make('testNumberInput3')
85+
->label('Number field with ->step(0.01)')
86+
->step(0.01),
87+
88+
Number::make('testNumberInput4')
89+
->label('Number field with ->step(10)')
90+
->step(10),
91+
92+
Email::make('inputEmail2')
93+
->label('Email field'),
94+
95+
Input::make('inputEmail3')
96+
->label('Input ->email() field')
97+
->email(),
98+
99+
Password::make('inputPassword2')
100+
->label('Password field with validation: ->min(8) and ->symbols()')
101+
->rules('required', 'string', 'max:255', \Illuminate\Validation\Rules\Password::min(8)->symbols()),
102+
103+
Input::make('inputPassword3')
104+
->label('Input ->password() field')
105+
->password(),
106+
107+
Date::make('inputDate4')
108+
->label('Input type: date - with extra FlatPicker date-options: { showMonths: 2 }')
109+
->date(['showMonths' => 2]),
110+
111+
Date::make('inputDate5')
112+
->label('Input type: date with time')
113+
->time(),
114+
115+
Date::make('inputDate6')
116+
->label('Input type: date with range')
117+
->range()
118+
->help('Test help 2'),
119+
120+
Time::make('inputTime1')
121+
->label('Input time field - with extra FlatPicker time-options: { time_24hr: false }')
122+
->time(['time_24hr' => false]),
123+
124+
Time::make('inputTime2')
125+
->label('Input type: time'),
126+
127+
Text::make('textField')
128+
->label('Text-input (Input-alias)'),
129+
130+
Text::make('disabledTextField')
131+
->label('Disabled text field')
132+
->disabled(),
133+
134+
Text::make('readonlyTextField')
135+
->label('Readony text field')
136+
->readonly(),
137+
138+
Text::make('disabledAndReadonlyTextField')
139+
->label('Disabled and readony text field')
140+
->disabled()
141+
->readonly(),
142+
143+
Textarea::make('testTextarea1')
144+
->label('Textarea'),
145+
146+
Checkbox::make('testCheckbox[]')->label('Checkbox 1')->value('checkbox-1'),
147+
Checkbox::make('testCheckbox[]')->label('Checkbox 2')->value('checkbox-2')->help('Test help 4'),
148+
149+
Radio::make('testRadio')->label('Radio 1')->value('radio-1'),
150+
Radio::make('testRadio')->label('Radio 2')->value('radio-2'),
151+
Radio::make('testRadio')->label('Radio 3')->value('radio-3')->help('Test help 5'),
152+
153+
Select::make('testSelect')
154+
->label('Choose a country')
155+
->placeholder('Placeholder...')
156+
->options([
157+
'be' => 'Belgium',
158+
'de' => 'Germany',
159+
'fr' => 'France',
160+
'lu' => 'Luxembourg',
161+
'nl' => 'The Netherlands',
162+
]),
163+
164+
Select::make('testSelectWithoutChoices')
165+
->label('Choose a country - choices(false)')
166+
->placeholder('Placeholder...')
167+
->options([
168+
'be' => 'Belgium',
169+
'de' => 'Germany',
170+
'fr' => 'France',
171+
'lu' => 'Luxembourg',
172+
'nl' => 'The Netherlands',
173+
])
174+
->choices(false),
175+
176+
Select::make('testSelectMultiple[]')
177+
->label('Choose multiple countries')
178+
->placeholder('Placeholder...')
179+
->options([
180+
'be' => 'Belgium',
181+
'de' => 'Germany',
182+
'fr' => 'France',
183+
'lu' => 'Luxembourg',
184+
'nl' => 'The Netherlands',
185+
])
186+
->multiple(),
187+
188+
Select::make('testSelectMultipleWithExtraChoicesOptions[]')
189+
->label('Choose multiple countries - with extra Choices.js-options: { searchEnabled: false }')
190+
->placeholder('Placeholder...')
191+
->options([
192+
'be' => 'Belgium',
193+
'de' => 'Germany',
194+
'fr' => 'France',
195+
'lu' => 'Luxembourg',
196+
'nl' => 'The Netherlands',
197+
])
198+
->multiple()
199+
->choices(['searchEnabled' => false]),
200+
201+
Select::make('testSelectMultipleWithoutChoices[]')
202+
->label('Choose multiple countries - choices(false)')
203+
->placeholder('Placeholder...')
204+
->options([
205+
'be' => 'Belgium',
206+
'de' => 'Germany',
207+
'fr' => 'France',
208+
'lu' => 'Luxembourg',
209+
'nl' => 'The Netherlands',
210+
])
211+
->multiple()
212+
->choices(false),
213+
214+
Select::make('fromRemoteUrl')
215+
->label('Select with data from a remote URL')
216+
->remoteUrl('/api/users1')
217+
->choices(false),
218+
219+
Select::make('fromRemoteUrlWithRemoteRoot')
220+
->label('Select with data from a remote URL with a remote root')
221+
->remoteUrl('/api/users2')
222+
->remoteRoute('data.users')
223+
->optionLabel('name')
224+
->optionValue('id')
225+
->choices(false),
226+
227+
Select::make('withOptionLabelAndValue')
228+
->label('Select with Option Label and Value')
229+
->options([
230+
['id' => 10, 'name' => 'Pascal'],
231+
['id' => 20, 'name' => 'Johan'],
232+
['id' => 30, 'name' => 'Olaf'],
233+
['id' => 40, 'name' => 'Kristof'],
234+
])
235+
->optionLabel('name')
236+
->optionValue('id')
237+
->choices(false)
238+
->help('Test help 6'),
239+
240+
Color::make('colorInput')
241+
->label('Color::make()'),
242+
243+
Submit::make()->label('Send'),
244+
];
245+
}
246+
}

app/app/Forms/ModelbindingForm.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Forms;
4+
5+
use ProtoneMedia\Splade\AbstractForm;
6+
use ProtoneMedia\Splade\FormBuilder\Datetime;
7+
use ProtoneMedia\Splade\FormBuilder\Select;
8+
use ProtoneMedia\Splade\FormBuilder\Submit;
9+
use ProtoneMedia\Splade\FormBuilder\Text;
10+
use ProtoneMedia\Splade\FormBuilder\Textarea;
11+
use ProtoneMedia\Splade\SpladeForm;
12+
13+
class ModelbindingForm extends AbstractForm
14+
{
15+
public function configure(SpladeForm $form)
16+
{
17+
$form
18+
->class('space-y-4')
19+
->action(route('formbuilder.model.store'));
20+
}
21+
22+
public function fields(): array
23+
{
24+
return [
25+
Datetime::make('publish_from')
26+
->label(__('Publish from')),
27+
28+
Text::make('title')
29+
->label(__('Title'))
30+
->required(),
31+
32+
Text::make('slug')
33+
->label(__('Slug'))
34+
->required(),
35+
36+
Textarea::make('body')
37+
->label(__('Body'))
38+
->autosize(),
39+
40+
Select::make('tags')
41+
->label(__('Tags'))
42+
->multiple()
43+
->choices()
44+
->options([
45+
'laravel' => 'laravel',
46+
'splade' => 'splade',
47+
'test' => 'test',
48+
'formbuilder' => 'formbuilder',
49+
'options' => 'options',
50+
]),
51+
52+
Submit::make()->label(__('Save')),
53+
];
54+
}
55+
}

app/app/Forms/MultiForm.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace App\Forms;
4+
5+
use ProtoneMedia\Splade\AbstractForm;
6+
use ProtoneMedia\Splade\FormBuilder\Checkboxes;
7+
use ProtoneMedia\Splade\FormBuilder\Radios;
8+
use ProtoneMedia\Splade\FormBuilder\Submit;
9+
use ProtoneMedia\Splade\SpladeForm;
10+
11+
class MultiForm extends AbstractForm
12+
{
13+
public function configure(SpladeForm $form)
14+
{
15+
$form
16+
->id('multiform1')
17+
->action(route('formbuilder.multifields1.store'))
18+
->fill([
19+
'testMultiCheckbox1' => [1],
20+
'testMultiCheckbox2' => ['option-2', 'option-3'],
21+
'testMultiRadio1' => 'light',
22+
]);
23+
}
24+
25+
public function fields(): array
26+
{
27+
return [
28+
Checkboxes::make('testMultiCheckbox1')
29+
->label('MultiCheckbox 1')
30+
->options([
31+
'Option 1',
32+
'Option 2',
33+
'Option 3',
34+
]),
35+
36+
Checkboxes::make('testMultiCheckbox2')
37+
->label('MultiCheckbox 2 (inline)')
38+
->options([
39+
'option-1' => 'Option 1',
40+
'option-2' => 'Option 2',
41+
'option-3' => 'Option 3',
42+
])
43+
->inline(),
44+
45+
Radios::make('testMultiRadio1')
46+
->label('Choose a theme')
47+
->options([
48+
'dark' => 'Dark theme',
49+
'light' => 'Light theme',
50+
'system' => 'System theme',
51+
]),
52+
53+
Radios::make('testMultiRadio2')
54+
->label('MultiRadio inline')
55+
->options([
56+
'option-1' => 'Option 1',
57+
'option-2' => 'Option 2',
58+
'option-3' => 'Option 3',
59+
])
60+
->class('testclass')
61+
->inline(),
62+
63+
Submit::make()->label('Send')->class('submit-btn'),
64+
];
65+
}
66+
}

0 commit comments

Comments
 (0)