Skip to content

Commit dbfb70e

Browse files
authored
update compatibility for custom field classes (#5)
* fix default value for select box * update compatibility for custom field classes * update compatibility for custom field classes
1 parent 3893e47 commit dbfb70e

File tree

16 files changed

+36
-31
lines changed

16 files changed

+36
-31
lines changed

src/Gustiawan/FormBuilder/Components/Form.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public function __construct($form)
2525
*/
2626
public function render()
2727
{
28-
$view = view('form-generator::components.tailwind.base');
29-
if (config('form_generator.style') == "bootstrap") {
30-
$view = view('form-generator::components.bootstrap.base');
31-
}
28+
$view = view('form-generator::components.base');
3229

3330
if (config('form_generator.form_template') != null) {
3431
return view(config('form_generator.form_template'));

src/Gustiawan/FormBuilder/Form.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ public function date(string $name, string $label, array $options=[])
110110
$this->fields[] = $this->parseField("date", $name, $label, $options);
111111
}
112112

113+
/**
114+
* Form Date Input
115+
*
116+
* @param string $name
117+
* @param string $label
118+
* @param array $options
119+
* @return void
120+
*/
121+
public function number(string $name, string $label, array $options=[])
122+
{
123+
$this->fields[] = $this->parseField("number", $name, $label, $options);
124+
}
125+
113126
/**
114127
* Form Text Area Input
115128
*
@@ -215,6 +228,7 @@ private function parseField(string $type, string $name, string $label, array $op
215228
"type" => $type,
216229
"name" => $name,
217230
"required" => array_key_exists("required", $options) ? $options['required'] : false,
231+
"class" => array_key_exists("class", $options) ? $options['class'] : "",
218232
];
219233

220234
if (array_key_exists("value", $options)) {

src/Gustiawan/FormBuilder/views/components/tailwind/base.blade.php renamed to src/Gustiawan/FormBuilder/views/components/base.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ class="flex justify-center"
66
@csrf
77
@endif
88

9-
@if($form->method != "POST" || $form->method != "GET")
9+
@if($form->method != "POST" && $form->method != "GET")
1010
@method($form->method)
1111
@endif
12+
@include('form-generator::components.' .config('form_generator.style'). '.inputs', ["form" => $form])
1213

13-
@include('form-generator::components.tailwind.inputs', ["form" => $form])
14+
{{ $slot }}
1415
</form>

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Gustiawan/FormBuilder/views/components/bootstrap/fields/checkbox.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@foreach($field['choices'] as $value => $choice)
22
<div class="form-check">
33
<input type="checkbox"
4-
class="form-check-input"
4+
class="form-check-input {{ $field['class'] }}"
55
name="{{ $field['name'] }}[]"
66
id="{{ $field['name']."-{$value}" }}"
77
value="{{ $value }}"

src/Gustiawan/FormBuilder/views/components/bootstrap/fields/input.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<input class="form-control"
1+
<input class="form-control {{ $field['class'] }}"
22
id="{{ $field['name'] }}"
33
type="{{ $field['type'] }}"
44
name="{{ $field['name'] }}"

src/Gustiawan/FormBuilder/views/components/bootstrap/fields/radio.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@foreach($field['choices'] as $value => $choice)
22
<div class="form-check">
33
<input type="radio"
4-
class="form-check-input"
4+
class="form-check-input {{ $field['class'] }}"
55
name="{{ $field['name'] }}"
66
value="{{ $value }}"
77
id="{{ $field['name']."-{$value}" }}"

src/Gustiawan/FormBuilder/views/components/bootstrap/fields/select.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<select name="{{ $field['name'] }}" id="{{ $field['name'] }}" class="form-control" {{ $field['required'] ? "required" : "" }}>
1+
<select name="{{ $field['name'] }}" id="{{ $field['name'] }}"
2+
class="form-control {{ $field['class'] }}"
3+
{{ $field['required'] ? "required" : "" }}
4+
>
25
<option value="">Select</option>
36
@foreach($field['choices'] as $value => $choice)
47
<option value="{{ $value }}" {{ (old($field['name']) ?? $field['value']) == $value ? "selected" : "" }} >{{ $choice }}</option>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<textarea name="{{ $field['name'] }}"
2-
class="form-control"
2+
class="form-control {{ $field['class'] }}"
33
id="{{ $field['name'] }}"
44
{{ $field['required'] ? "required" : "" }}
55
>{{ old($field['name']) ?? $field['value'] }}</textarea>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@foreach($form->fields as $field)
22
<div class="form-group">
33
<label for="{{ $field['name'] }}" class="font-weight-bold">{!! $field['label'] !!}</label>
4-
@if( !in_array($field['type'], ["text", "date", "password"]))
4+
@if( !in_array($field['type'], ["text", "date", "password", "number"]))
55
@include('form-generator::components.bootstrap.fields.'.$field['type'], ["field" => $field])
66
@else
77
@include('form-generator::components.bootstrap.fields.input', ["field" => $field])

0 commit comments

Comments
 (0)