|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* HiPanel core package |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://hipanel.com/ |
|
7
|
|
|
* @package hipanel-core |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hipanel\widgets; |
|
13
|
|
|
|
|
14
|
|
|
use hipanel\helpers\ArrayHelper; |
|
15
|
|
|
use hiqdev\combo\Combo; |
|
16
|
|
|
use Yii; |
|
17
|
|
|
use yii\helpers\Html; |
|
18
|
|
|
use yii\widgets\ActiveField; |
|
19
|
|
|
|
|
20
|
|
|
class AdvancedSearchActiveField extends ActiveField |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_inputId; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
public function widget($class, $config = []) |
|
28
|
|
|
{ |
|
29
|
|
|
/* @var $class \yii\base\Widget */ |
|
30
|
|
|
$config['class'] = $class; |
|
31
|
|
|
$config['model'] = $this->model; |
|
32
|
|
|
$config['attribute'] = $this->attribute; |
|
33
|
|
|
$config['view'] = $this->form->getView(); |
|
34
|
|
|
$widget = Yii::createObject($config); |
|
35
|
|
|
|
|
36
|
|
|
if ($widget instanceof Combo) { |
|
37
|
|
|
$this->_inputId = $this->_inputId ?: ($this->getInputId() . '-' . mt_rand()); |
|
38
|
|
|
$widget->inputOptions['id'] = $this->getInputId(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->parts['{input}'] = $widget->run(); |
|
42
|
|
|
|
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getInputId() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->_inputId ?: parent::getInputId(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Renders the opening tag of the field container. |
|
53
|
|
|
* @return string the rendering result. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function begin() |
|
56
|
|
|
{ |
|
57
|
|
|
if ($this->form->enableClientScript) { |
|
58
|
|
|
$clientOptions = $this->getClientOptions(); |
|
59
|
|
|
if (!empty($clientOptions)) { |
|
60
|
|
|
$this->form->attributes[] = $clientOptions; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$inputID = $this->getInputId(); |
|
65
|
|
|
$attribute = Html::getAttributeName($this->attribute); |
|
66
|
|
|
$options = $this->options; |
|
67
|
|
|
$class = isset($options['class']) ? [$options['class']] : []; |
|
68
|
|
|
$class[] = "field-$inputID"; |
|
69
|
|
|
if ($this->model->isAttributeRequired($attribute)) { |
|
70
|
|
|
$class[] = $this->form->requiredCssClass; |
|
71
|
|
|
} |
|
72
|
|
|
if ($this->model->hasErrors($attribute)) { |
|
73
|
|
|
$class[] = $this->form->errorCssClass; |
|
74
|
|
|
} |
|
75
|
|
|
$options['class'] = implode(' ', $class); |
|
76
|
|
|
|
|
77
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'div'); |
|
78
|
|
|
// Added tooltip help |
|
79
|
|
|
$options['data'] = [ |
|
80
|
|
|
'toggle' => 'tooltip', |
|
81
|
|
|
'title' => $this->model->getAttributeLabel($this->attribute), |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
return Html::beginTag($tag, $options); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|