File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
resources/views/default/element Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 1212
1313class Checkbox extends Element
1414{
15- protected $ options = [];
15+ protected $ options = [];
16+ protected $ nullable = false ;
1617
1718 public function view ()
1819 {
@@ -25,12 +26,28 @@ public function view()
2526 'checked ' => $ this ->value ,
2627 'options ' => $ this ->options ,
2728 'class ' => $ this ->class ,
28- 'attributes ' => $ this ->attributes
29+ 'attributes ' => $ this ->attributes ,
30+ 'nullable ' => $ this ->nullable ,
2931 ]);
3032 }
3133
3234 public function value ()
3335 {
34- return $ this ->value ? 1 : 0 ;
36+ $ value = null ;
37+
38+ if ($ this ->value ) {
39+ $ value = 1 ;
40+ } elseif (!$ this ->nullable ) {
41+ $ value = 0 ;
42+ }
43+
44+ return $ value ;
45+ }
46+
47+ public function nullable ($ nullable = true )
48+ {
49+ $ this ->nullable = $ nullable ;
50+
51+ return $ this ;
3552 }
3653}
Original file line number Diff line number Diff line change 11<div class =" form__element form__element_type_checkbox @if ($error ) form__element_error @endif {{ $class } }" >
22 <label class =" form__label" >
3- <input type =" hidden" value =" 0" name =" {{ $elementName } }" >
3+ @if (! $nullable )
4+ <input type =" hidden" value =" 0" name =" {{ $elementName } }" >
5+ @endif
46 <input @foreach ($attributes as $attributeName => $attributeValue ) {{ $attributeName } } =" {{ $attributeValue } }" @endforeach type =" checkbox" value =" 1" @if ($checked ) checked =" checked" @endif name =" {{ $elementName } }" > <span >{{ $label } } </span >
57 <div class =" form__help" >{{ $help } } </div >
68 <div class =" form__feedback" >{{ $error } } </div >
You can’t perform that action at this time.
0 commit comments