diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Color.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Color.php index 056c68dc16a..62f40005486 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Color.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Color.php @@ -33,11 +33,21 @@ class Mage_Adminhtml_Model_System_Config_Backend_Color extends Mage_Core_Model_C */ protected function _beforeSave() { + /** @var Mage_Core_Model_Config_Element $config */ $config = $this->getFieldConfig(); + $validate = []; + if (isset($config->validate)) { + $validate = array_map('trim', explode(' ', $config->validate)); + } + + if (!(string)$this->getValue() && !in_array('required-entry', $validate)) { + return $this; + } + $with_hash = true; if (isset($config->with_hash)) { - $with_hash = (bool)$config->with_hash; + $with_hash = $config->is('with_hash', true); } if ($with_hash) { diff --git a/lib/Varien/Data/Form/Element/Color.php b/lib/Varien/Data/Form/Element/Color.php index eb1f97e1f08..77327ecf342 100644 --- a/lib/Varien/Data/Form/Element/Color.php +++ b/lib/Varien/Data/Form/Element/Color.php @@ -54,9 +54,10 @@ public function getHtmlAttributes() public function getElementHtml() { $id = $this->getHtmlId(); - $with_hash = (bool) ($this->original_data['with_hash'] ?? 1); - if ($with_hash) { + $with_hash = strtolower((string) ($this->original_data['with_hash'] ?? 1)); + + if (!empty($with_hash) && $with_hash !== 'false' && $with_hash !== 'off') { $oninput = "document.getElementById('{$id}').value = this.value"; $regex = self::VALIDATION_REGEX_WITH_HASH; $this->setOninput("document.getElementById('{$id}:html5').value = {$regex}.test(this.value) ? this.value : '#000000'");