Skip to content
Snippets Groups Projects
Commit 03a6e0a4 authored by aydreeihn's avatar aydreeihn
Browse files

Issue: Saving Checkbox Values

This commit fixes an issue where checkboxes could not be edited for inline edit or all field edits.

When a BooleanField is directly passed to the to_database method, you are not able to accurately check to see if old != new. To fix this, I added a new getChanges method to the BooleanField class that will first do a comparison on the raw boolean value (true, false) and then get the value needed for the database. I then made sure that we use that new function when editing all fields together.

Additionally, I added a getClean method to the BooleanField class so that $this->_clean for the field would be set to either true or NULL depending on if the box is checked or not and would accurately save to the database when calling $form->saveAnswers()
parent 78a673fb
Branches
Tags
No related merge requests found
......@@ -1194,11 +1194,10 @@ class DynamicFormEntry extends VerySimpleModel {
$field = $a->getField();
if (!$field->hasData() || $field->isPresentationOnly())
continue;
$after = $field->to_database($field->getClean());
$before = $field->to_database($a->getValue());
if ($before == $after)
$changes = $field->getChanges();
if (!$changes)
continue;
$fields[$field->get('id')] = array($before, $after);
$fields[$field->get('id')] = $changes;
}
return $fields;
}
......
......@@ -1677,6 +1677,24 @@ class BooleanField extends FormField {
return ($value) ? __('Yes') : __('No');
}
function getClean($validate=true) {
if (!isset($this->_clean)) {
$this->_clean = (isset($this->value))
? $this->value : $this->getValue();
if ($this->isVisible() && $validate)
$this->validateEntry($this->_clean);
}
return $this->_clean;
}
function getChanges() {
$new = $this->getValue();
$old = $this->answer ? $this->answer->getValue() : $this->get('default');
return ($old != $new) ? array($this->to_database($old), $this->to_database($new)) : false;
}
function getSearchMethods() {
return array(
'set' => __('checked'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment