-
Notifications
You must be signed in to change notification settings - Fork 638
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
[4.x]: CP checkboxSelect.twig
not sending empty values
#11748
Comments
This surprised me a little since we use Turns out they do, but only if you pass {% import "_includes/forms" as forms %}
{{ forms.checkboxSelect({
name: 'foo',
showAllOption: true,
}) }} I’ve just updated the template to start posting an empty value regardless of |
I can confirm, with "showAllOption" it does work. It doesn't make sense in our case, but at least I can work around it. Thank you very much! |
I found another temporary workaround. I am outputting a hidden input field before the checkboxes: return '<input type="hidden" name="' . $this->handle . '" value="">' . Craft::$app->getView()
->renderTemplate('_includes/forms/checkboxSelect', [
'name' => $this->handle,
'values' => $value !== null ? $value->ids() : [],
'options' => $options,
]); |
Yep that’s exactly what will happen in 4.3. Your code won’t break, but after 4.3 it will be safe to remove that extra hidden input. |
What happened?
Description
I am using a custom field in the CP. It displays the available category groups. When displaying these category groups with
multiselect.twig
, everythings works as expected. But since I don't like the usability of multi selects, I want to use the multi checkbox layout.I can see in the network pane, that when sending a new selection, the field is submitted with values.
When deselecting everything, nothing is sent for this field. That, I guess, is the problem. Comparing it to multiselct, an empty value is sent:
Steps to reproduce
checkboxSelect.twig
as input htmlExpected behavior
Everything is unselected.
Actual behavior
The last state is restored, when deselecting everything.
Craft CMS version
4.2.0.2
PHP version
8.1
Operating system and version
MacOS
Database type and version
MariaDB 10.5
Image driver and version
Installed plugins and versions
The text was updated successfully, but these errors were encountered: