Skip to content

Commit e5c49d2

Browse files
authored
Fixing checkbox not remembering its previous state (#564)
1 parent 286f671 commit e5c49d2

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

resources/views/components/input/checkbox.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
'class' => "filled-in checkbox-color",
99
'name' => $id
1010
])}}
11-
@checked(old($id) || $checked)
11+
@checked(in_array($attributes['value'], (old($id)['option'] ?? []))
12+
|| $checked)
1213
>
1314
<span>{{$label}}</span>
1415
</label>

resources/views/secretariat/evaluation-form/anonymous_questions.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
<x-input.radio :name="$question->formKey()" value="{{$option->id}}" text="{{$option->title}}"
3232
:checked="old($question->formKey()) == $option->id" />
3333
@else
34-
<x-input.checkbox :name="$question->formKey().'[]'" value="{{$option->id}}" text="{{$option->title}}"
35-
:checked="!is_null(old($question->formKey()))
36-
&& in_array($option->id, old($question->formKey()))" />
34+
<x-input.checkbox :id="$question->formKey()" :name="$question->formKey().'[]'" value="{{$option->id}}" text="{{$option->title}}"
35+
{{-- for some reason, having a custom id changes the structure of old($id) --}}
36+
:checked="in_array($option->id, (old($question->formKey()) ?? []))" />
3737
@endif
3838
@endforeach
3939
@endif

resources/views/utils/question_card.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<span class="card-title">@lang('voting.new_question')</span>
1111
<div class="row">
12-
<x-input.text s="12" type="text" text="voting.question_title" id="title" maxlength="100" required/>
12+
<x-input.text s="12" type="text" text="voting.question_title" id="title" maxlength="250" required/>
1313
</div>
1414
<div class="row">
1515
@livewire('parent-child-form', ['title' => __('voting.options'), 'name' => 'options', 'items' => old('options')])

0 commit comments

Comments
 (0)