Enh: Added random default color to humhub\modules\ui\form\widgets\ColorPicker

This commit is contained in:
buddh4 2018-08-23 19:58:21 +02:00
parent 12e3e5addf
commit 57443b20ae
2 changed files with 14 additions and 0 deletions

View File

@ -19,6 +19,9 @@ HumHub Change Log
- Enh: Added `grunt test-server` and `grunt test`
- Chng: `humhub\modules\content\models\Content` now implements `humhub\modules\content\interfaces\ContentOwner`
- Fix: Target container not available in `humhub\modules\content\components\ContentActiveRecord:afterMove()`
- Chng: `humhub\modules\topic\models\Topic::attach` now accepts `humhub\modules\content\interfaces\ContentOwner` instances
- Fix: Richtext without focusMenu on small devices overlaps previous sibling
- Enh: Added random default color to `humhub\modules\ui\form\widgets\ColorPicker`

View File

@ -8,6 +8,7 @@
namespace humhub\modules\ui\form\widgets;
use Colors\RandomColor;
use humhub\modules\ui\form\widgets\JsInputWidget;
/**
@ -34,6 +35,11 @@ class ColorPicker extends JsInputWidget
*/
public $attribute = 'color';
/**
* @var bool If set to true, a random color will be set as default
*/
public $randomDefault = true;
/**
* @inheritdoc
*/
@ -42,6 +48,11 @@ class ColorPicker extends JsInputWidget
if (!empty($this->field)) {
$this->attribute = $this->field;
}
if($this->hasModel() && !$this->getValue() && $this->randomDefault) {
$attr = $this->attribute;
$this->model->$attr = RandomColor::one(['luminosity' => 'dark']);
}
}
/**