forked from worstinme/yii2-uikit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveField.php
58 lines (38 loc) · 1.77 KB
/
ActiveField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace worstinme\uikit;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
class ActiveField extends \yii\widgets\ActiveField
{
public $template = "{label}\n<div class=\"uk-form-controls\">{input}\n{error}\n{hint}\n</div>\n";
public $labelOptions = ['class' => 'uk-form-label'];
public $options = ['class' => 'uk-form-row'];
public $errorOptions = ['class' => 'uk-form-help-block uk-text-danger'];
public $hintOptions = ['class' => 'uk-form-help-block'];
public function begin()
{
$attribute = Html::getAttributeName($this->attribute);
if ($this->model->hasErrors($attribute)) {
$this->inputOptions['class'] .= ' uk-form-danger';
}
return parent::begin();
}
public function checkbox($options = [], $enclosedByLabel = true)
{
return parent::checkbox($options, $enclosedByLabel);
}
public function aliasInput($related, $options = [])
{
$related_id = '#'.Html::getInputId($this->model, $related);
$alias_id = '#'.$this->getInputId();
$view = $this->form->getView();
$url = \yii\helpers\Url::toRoute(['alias-create']);
$script = "$('body').on('change','$related_id',function(){ $.post('$url',{name:$('$related_id').val()},function(data){ if ($('$alias_id').val()) { UIkit.modal.confirm('Replace alias? '+data.alias, function(){ $('$alias_id').val(data.alias) }); } else $('$alias_id').val(data.alias)} )});";
$view->registerJs($script,$view::POS_READY);
\worstinme\uikit\assets\Notify::register($view);
$options = array_merge($this->inputOptions, $options);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeTextInput($this->model, $this->attribute, $options);
return $this;
}
}