Skip to content

Fixing checkbox not remembering its previous state; as well as too short question titles #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/views/components/input/checkbox.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
'class' => "filled-in checkbox-color",
'name' => $id
])}}
@checked(old($id) || $checked)
@checked(in_array($attributes['value'], (old($id)['option'] ?? []))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this with the other checkbox instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; with the "remember me" field and voting, it seems to work.

|| $checked)
>
<span>{{$label}}</span>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<x-input.radio :name="$question->formKey()" value="{{$option->id}}" text="{{$option->title}}"
:checked="old($question->formKey()) == $option->id" />
@else
<x-input.checkbox :name="$question->formKey().'[]'" value="{{$option->id}}" text="{{$option->title}}"
:checked="!is_null(old($question->formKey()))
&& in_array($option->id, old($question->formKey()))" />
<x-input.checkbox :id="$question->formKey()" :name="$question->formKey().'[]'" value="{{$option->id}}" text="{{$option->title}}"
{{-- for some reason, having a custom id changes the structure of old($id) --}}
:checked="in_array($option->id, (old($question->formKey()) ?? []))" />
@endif
@endforeach
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/utils/question_card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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