processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

InputfieldFile::getItemInputfields() does not check against value 0 to uncheck a checkbox if checked is default.

Open kixe opened this issue 8 months ago • 2 comments

Short description of the issue

InputfieldFile::getItemInputfields() does not check against the value 0 to uncheck a checkbox if "checked" is the default value. This doesn't matter for the core type of FieldtypeCheckbox, as the "checked by default" option is still not available (which is a lack of default functionality). I use a custom FieldtypeCheckbox that always submit and stores the value (checked = 1, unchecked = 0) which allows to provide the "checked by default" option in field settings. https://github.com/kixe/FieldtypeCheckboxExtended

Expected behavior

If custom file / image field is of type Checkbox, the attribute 'checked' should be removed if value is empty, because it can be checked by default.

Actual behavior

Currently the function InputfieldFile::getItemInputfields() only adds the attribute if the value is not empty.

Optional: Suggestion for a possible fix

Would be great to add the following line

 // add after LINE 1572 if($value) $f->attr('checked', 'checked');
else if(!$value) $f->attr('checked', ''); // remove if previously assigned

Setup/Environment

  • ProcessWire version: 3.0.239
  • PHP version: 8.2
  • 3rd party module: https://github.com/kixe/FieldtypeCheckboxExtended

kixe avatar Jun 17 '24 06:06 kixe