/
translitInput.php
67 lines (49 loc) · 1.69 KB
/
translitInput.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
59
60
61
62
63
64
65
66
67
<?php
/**
* Created by PhpStorm.
* User: vadim
* Date: 11.02.16
* Time: 14:48
*/
namespace sibds\widgets;
use kartik\icons\Icon;
use sibds\widgets\synctranslit\Assets;
use yii\bootstrap5\Html;
use yii\bootstrap5\InputWidget;
class translitInput extends InputWidget
{
public $fromField;
public $template = '{icon}{input}';
public $icon = 'link';
public $translitOptions = [];
public function run(){
echo Html::beginTag('div', ['class'=>'input-group']);
if(!isset($this->options['class']))
$this->options['class'] = 'form-control';
$iconId = 'icon-'.$this->options['id'];
if(!isset($this->options['aria-describedby']))
$this->options['aria-describedby'] = $iconId;
if ($this->hasModel()) {
$replace['{input}'] = Html::activeTextInput($this->model, $this->attribute, $this->options);
} else {
$replace['{input}'] = Html::textInput($this->name, $this->value, $this->options);
}
if($this->icon!='')
$replace['{icon}'] = Html::tag('span',
Icon::show($this->icon, [], Icon::FA),
['class'=>'input-group-text', 'id'=>$iconId]);
echo strtr($this->template, $replace);
echo Html::endTag('div');
$view = $this->getView();
Assets::register($view);
$idMaster = $this->hasModel() ? Html::getInputId($this->model, $this->fromField) : $this->fromField;
$idSlave = $this->options['id'];
$view->registerJs("
$('#$idMaster').syncTranslit({
destination: '$idSlave',
type: 'url',
caseStyle: 'lower',
urlSeparator: '-'
});");
}
}