Skip to content

Commit

Permalink
Check value on colorpicker (#5689)
Browse files Browse the repository at this point in the history
* Check value on colorpicker

* Update CHANGELOG.md (#5689)
  • Loading branch information
yurabakhtin committed May 11, 2022
1 parent 513e0e7 commit adcc7f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@ HumHub Changelog
- Fix #5657: Fix links of user counters in container headers
- Fix #5676: Use 404 page for deleted content request
- Fix #5679: Fix message on decline multiple users

- Fix #5689: Check value on colorpicker

1.11.1 (April 22, 2022)
-----------------------
Expand Down
8 changes: 7 additions & 1 deletion protected/humhub/modules/ui/form/widgets/ColorPicker.php
Expand Up @@ -49,7 +49,8 @@ public function init()
$this->attribute = $this->field;
}

if($this->hasModel() && !$this->getValue() && $this->randomDefault) {
if (($this->hasModel() && !$this->getValue() && $this->randomDefault) ||
!$this->isCorrectColorValue()) {
$attr = $this->attribute;
$this->model->$attr = RandomColor::one(['luminosity' => 'dark']);
}
Expand All @@ -68,4 +69,9 @@ public function run()
]);
}

private function isCorrectColorValue(): bool
{
return preg_match('/^#[a-f0-9]{3,6}$/i', $this->model->{$this->attribute});
}

}

0 comments on commit adcc7f2

Please sign in to comment.