From 8239e0b11e0fa1991b5d873c3db2df2a27b04de3 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 12 Jun 2020 12:49:38 -0400 Subject: [PATCH] Some refactoring in InputfieldCheckbox.module --- .../Inputfield/InputfieldCheckbox.module | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldCheckbox.module b/wire/modules/Inputfield/InputfieldCheckbox.module index c45cfc73..68fe036b 100644 --- a/wire/modules/Inputfield/InputfieldCheckbox.module +++ b/wire/modules/Inputfield/InputfieldCheckbox.module @@ -40,6 +40,7 @@ class InputfieldCheckbox extends Inputfield { * */ public function __construct() { + $this->set('checkedValue', self::checkedValueDefault); $this->checkedValueIsLabel = false; // cancel line above $this->set('uncheckedValue', self::uncheckedValueDefault); @@ -54,13 +55,23 @@ class InputfieldCheckbox extends Inputfield { $this->set('labelAttrs', array()); // Optional attributes for "; return $out; } - /* TBA: May move to be a separate 'toggle' Inputfield, keeping for reference - public function ___renderRadio() { - - $attrs = $this->getAttributes(); - - $attrs['value'] = $this->checkedValue; - $attrs['checked'] = $this->attr('value') == $this->checkedValue ? 'checked' : ''; - if(empty($attrs['checked'])) unset($attrs['checked']); - $label = $this->entityEncode($this->checkedValue); - $out = "\n "; - - $attrs['value'] = $this->uncheckedValue; - $attrs['checked'] = $this->attr('value') == $this->uncheckedValue ? 'checked' : ''; - if(empty($attrs['checked'])) unset($attrs['checked']); - $label = $this->entityEncode($this->uncheckedValue); - $out .= "\n "; - - return $out; - } - */ - /** * Render value only * @@ -240,7 +245,6 @@ class InputfieldCheckbox extends Inputfield { * */ public function isEmpty() { - // return $this->attr('value') != $this->checkedValue; return !$this->checked(); } @@ -255,6 +259,7 @@ class InputfieldCheckbox extends Inputfield { $value = $input[$this->name]; $checked = $this->isChecked(); + if(!empty($value)) { if(!$checked) $this->trackChange('value', $this->uncheckedValue, $this->checkedValue); parent::attr('checked', 'checked');