Skip to content

Commit 9603bbd

Browse files
authored
add form separator (#9)
1 parent 27d5914 commit 9603bbd

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/Gustiawan/FormBuilder/Form.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ public function button(string $label="Submit", string $color="bg-blue-500")
222222
$this->button["color"] = $color;
223223
}
224224

225+
/**
226+
* Add Separator to form
227+
*
228+
* @param string $label
229+
* @return void
230+
*/
231+
public function separator(string $label='')
232+
{
233+
$this->fields[] = $this->parseField('separator', 'separator', $label, []);
234+
}
235+
225236
/**
226237
* check if form need csrf
227238
*

src/Gustiawan/FormBuilder/views/components/base.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class="flex justify-center"
1212
@if($form->method != "POST" && $form->method != "GET")
1313
@method($form->method)
1414
@endif
15-
@include('form-generator::components.' .config('form_generator.style'). '.inputs', ["form" => $form])
15+
@include('form-generator::components.' . config('form_generator.style') . '.inputs', ["form" => $form])
1616

1717
{{ $slot }}
1818
</form>

src/Gustiawan/FormBuilder/views/components/bootstrap/inputs.blade.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
@foreach($form->fields as $field)
2+
@if ($field['type'] == 'separator')
3+
<div class="form-group" style="margin-top: 3em; margin-bottom: 2em;">
4+
@if ($field['label'] != '')
5+
<label class="font-weight-bold">{{ $field['label'] }}</label>
6+
@endif
7+
<hr />
8+
</div>
9+
@continue
10+
@endif
211
<div class="form-group">
312
<label for="{{ $field['name'] }}" class="font-weight-bold">{!! $field['label'] !!}</label>
4-
@if( !in_array($field['type'], ["text", "date", "password", "number", "file"]))
5-
@include('form-generator::components.bootstrap.fields.'.$field['type'], ["field" => $field])
6-
@else
13+
@if(in_array($field['type'], ["text", "date", "password", "number", "file"]))
714
@include('form-generator::components.bootstrap.fields.input', ["field" => $field])
15+
@else
16+
@include('form-generator::components.bootstrap.fields.'.$field['type'], ["field" => $field])
817
@endif
918
</div>
1019
@endforeach

src/Gustiawan/FormBuilder/views/components/tailwind/inputs.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<div class="w-full">
22
@foreach($form->fields as $field)
3+
@if ($field['type'] == 'separator')
4+
<div class="mb-4 my-3">
5+
@if ($field['label'] != '')
6+
<label class="ml-1">{!! $field['label'] !!}</label>
7+
@endif
8+
<hr />
9+
</div>
10+
@continue
11+
@endif
12+
313
<div class="mb-4">
414
<label class="ml-1">{!! $field['label'] !!}</label>
515
@if( !in_array($field['type'], ["text", "date", "password", "number", "file"]))

0 commit comments

Comments
 (0)