Skip to content

Commit a497e12

Browse files
committed
add compatibility for readonly and disabled
1 parent dbfb70e commit a497e12

File tree

11 files changed

+24
-2
lines changed

11 files changed

+24
-2
lines changed

src/Gustiawan/FormBuilder/Form.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ private function parseField(string $type, string $name, string $label, array $op
228228
"type" => $type,
229229
"name" => $name,
230230
"required" => array_key_exists("required", $options) ? $options['required'] : false,
231+
"readonly" => array_key_exists("readonly", $options) ? $options['readonly'] : false,
232+
"disabled" => array_key_exists("disabled", $options) ? $options['disabled'] : false,
231233
"class" => array_key_exists("class", $options) ? $options['class'] : "",
232234
];
233235

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class="form-check-input {{ $field['class'] }}"
55
name="{{ $field['name'] }}[]"
66
id="{{ $field['name']."-{$value}" }}"
77
value="{{ $value }}"
8+
{{ $field['readonly'] ? "readonly" : "" }}
9+
{{ $field['disabled'] ? "disabled" : "" }}
810
{{ in_array($value, (old($field['name']) ?? $field['value'])) ? "checked" : "" }}>
911
<label class="form-check-label" for="{{ $field['name']."-{$value}" }}">{{ $choice }}</label>
1012
</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
type="{{ $field['type'] }}"
44
name="{{ $field['name'] }}"
55
value="{{ old($field['name']) ?? $field['value'] }}"
6+
{{ $field['readonly'] ? "readonly" : "" }}
7+
{{ $field['disabled'] ? "disabled" : "" }}
68
{{ $field['required'] ? "required" : "" }}>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ class="form-check-input {{ $field['class'] }}"
66
value="{{ $value }}"
77
id="{{ $field['name']."-{$value}" }}"
88
{{ (old($field['name']) ?? $field['value']) == $value ? "checked" : "" }}
9-
{{ $field['required'] ? "required" : "" }}>
9+
{{ $field['required'] ? "required" : "" }}
10+
{{ $field['readonly'] ? "readonly" : "" }}
11+
{{ $field['disabled'] ? "disabled" : "" }}>
1012
<label class="form-check-label" for="{{ $field['name']."-{$value}" }}">{{ $choice }}</label>
1113
</div>
1214
@endforeach

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<select name="{{ $field['name'] }}" id="{{ $field['name'] }}"
22
class="form-control {{ $field['class'] }}"
33
{{ $field['required'] ? "required" : "" }}
4+
{{ $field['readonly'] ? "readonly" : "" }}
5+
{{ $field['disabled'] ? "disabled" : "" }}
46
>
57
<option value="">Select</option>
68
@foreach($field['choices'] as $value => $choice)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
class="form-control {{ $field['class'] }}"
33
id="{{ $field['name'] }}"
44
{{ $field['required'] ? "required" : "" }}
5+
{{ $field['readonly'] ? "readonly" : "" }}
6+
{{ $field['disabled'] ? "disabled" : "" }}
57
>{{ old($field['name']) ?? $field['value'] }}</textarea>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
class="form-checkbox bg-gray-200 {{ $field['class'] }}"
77
name="{{ $field['name'] }}[]"
88
value="{{ $value }}"
9+
{{ $field['readonly'] ? "readonly" : "" }}
10+
{{ $field['disabled'] ? "disabled" : "" }}
911
{{ in_array($value, (old($field['name']) ?? $field['value'])) ? "checked" : "" }}>
1012
<span class="ml-2">{{ $choice }}</span>
1113
</label>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
type="{{ $field['type'] }}"
33
name="{{ $field['name'] }}"
44
value="{{ old($field['name']) ?? $field['value'] }}"
5+
{{ $field['readonly'] ? "readonly" : "" }}
6+
{{ $field['disabled'] ? "disabled" : "" }}
57
{{ $field['required'] ? "required" : "" }}>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class="form-radio bg-gray-200 {{ $field['class'] }}"
77
name="{{ $field['name'] }}"
88
value="{{ $value }}"
99
{{ (old($field['name']) ?? $field['value']) == $value ? "checked" : "" }}
10-
{{ $field['required'] ? "required" : "" }}>
10+
{{ $field['required'] ? "required" : "" }}
11+
{{ $field['readonly'] ? "readonly" : "" }}
12+
{{ $field['disabled'] ? "disabled" : "" }}>
1113
<span class="ml-2">{{ $choice }}</span>
1214
</label>
1315
</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<select name="{{ $field['name'] }}"
22
class="mt-2 p-2 form-select w-full border {{ $field['class'] }}"
33
{{ $field['required'] ? "required" : "" }}
4+
{{ $field['readonly'] ? "readonly" : "" }}
5+
{{ $field['disabled'] ? "disabled" : "" }}
46
>
57
<option value="">Select</option>
68
@foreach($field['choices'] as $value => $choice)

0 commit comments

Comments
 (0)