Skip to content

Commit

Permalink
Topic pr 2945 - backend validation (OpenMage#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbeaty authored Jan 17, 2023
1 parent 535c02e commit d5dba71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions lib/Varien/Data/Form/Element/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down

0 comments on commit d5dba71

Please sign in to comment.