mirror of
https://github.com/humhub/humhub.git
synced 2025-01-18 06:38:14 +01:00
Added own ActiveField class in ActiveForm
This commit is contained in:
parent
28509a6d28
commit
0eabbdca7b
@ -22,4 +22,9 @@ class ActiveForm extends \yii\bootstrap\ActiveForm
|
||||
*/
|
||||
public $enableClientValidation = false;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $fieldClass = 'humhub\widgets\ActiveField';
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\widgets;
|
||||
|
||||
use humhub\components\Widget;
|
||||
|
||||
use yii\base\Widget;
|
||||
/**
|
||||
* Description of JsWidget
|
||||
*
|
||||
@ -11,19 +12,20 @@ use yii\base\Widget;
|
||||
*/
|
||||
class JsWidget extends Widget
|
||||
{
|
||||
|
||||
/**
|
||||
* Defines the select input field id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
|
||||
/**
|
||||
* Js Widget namespace
|
||||
* @var type
|
||||
*/
|
||||
public $jsWidget;
|
||||
|
||||
|
||||
/*
|
||||
* Used to overwrite select input field attributes. This array can be used for overwriting
|
||||
* texts, or other picker settings.
|
||||
@ -31,75 +33,76 @@ class JsWidget extends Widget
|
||||
* @var string
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
|
||||
/**
|
||||
* Event action handler.
|
||||
* @var type
|
||||
*/
|
||||
public $events = [];
|
||||
|
||||
|
||||
/**
|
||||
* Auto init flag.
|
||||
* @var mixed
|
||||
*/
|
||||
public $init = false;
|
||||
|
||||
|
||||
/**
|
||||
* Used to hide/show the actual input element.
|
||||
* @var type
|
||||
*/
|
||||
public $visible = true;
|
||||
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$attributes = $this->getAttributes();
|
||||
$attributes['data'] = $this->getData();
|
||||
$attributes['id'] = $this->getId();
|
||||
|
||||
|
||||
$this->setDefaultOptions();
|
||||
|
||||
$result = \yii\helpers\ArrayHelper::merge($attributes, $this->options);
|
||||
|
||||
if(!$this->visible) {
|
||||
if(isset($result['style'])) {
|
||||
|
||||
$result = \yii\helpers\ArrayHelper::merge($attributes, $this->options);
|
||||
|
||||
if (!$this->visible) {
|
||||
if (isset($result['style'])) {
|
||||
$result['style'] .= ';display:none;';
|
||||
} else {
|
||||
$result['style'] = 'display:none;';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setDefaultOptions()
|
||||
{
|
||||
|
||||
public function setDefaultOptions()
|
||||
{
|
||||
// Set event data
|
||||
foreach($this->events as $event => $handler) {
|
||||
$this->options['data']['widget-action-'.$event] = $handler;
|
||||
foreach ($this->events as $event => $handler) {
|
||||
$this->options['data']['widget-action-' . $event] = $handler;
|
||||
}
|
||||
|
||||
|
||||
$this->options['data']['ui-widget'] = $this->jsWidget;
|
||||
|
||||
if(!empty($this->init)) {
|
||||
|
||||
if (!empty($this->init)) {
|
||||
$this->options['data']['ui-init'] = $this->init;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getId($autoGenerate = true)
|
||||
{
|
||||
if($this->id) {
|
||||
if ($this->id) {
|
||||
return $this->id;
|
||||
}
|
||||
return parent::getId($autoGenerate);
|
||||
}
|
||||
|
||||
protected function getData()
|
||||
|
||||
protected function getData()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
protected function getAttributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user