Skip to content

Commit 7970ce2

Browse files
committed
js fixes
1 parent f157873 commit 7970ce2

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/lib/MaterializeWidgetTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function registerClientEvents()
103103
/** @var View $view */
104104
$view = $this->getView();
105105
$id = $this->options['id'];
106-
$js[] = "var elem_$id = document.getElementById('$id');";
106+
$js[] = "let elem_$id = document.getElementById('$id');";
107107
foreach ($this->clientEvents as $event => $handler) {
108108
$js[] = "elem_$id.addEventListener('$event', $handler);";
109109
}

src/widgets/form/RangeInput.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function init()
131131
}
132132

133133
if (!isset($this->sliderOptions['id'])) {
134-
$this->sliderOptions['id'] = $this->getId();
134+
$this->sliderOptions['id'] = "{$this->getId()}-slider";
135135
}
136136

137137
$this->addUpdateEvent();
@@ -145,14 +145,15 @@ public function init()
145145
*/
146146
protected function addUpdateEvent()
147147
{
148+
$containerId = $this->options['id'];
148149
$sliderId = $this->sliderOptions['id'];
149150
$this->inputOptions['data-slider-target'] = $sliderId;
150151

151152
if (!isset($this->clientEvents['update'])) {
152153
$this->clientEvents['update'] = new JsExpression(<<<JS
153154
function (values, handle) {
154-
var value = values[handle];
155-
$('[data-slider-target="{$sliderId}"]').val(value);
155+
let value = values[handle];
156+
document.querySelector('#$containerId [data-slider-target="{$sliderId}"]').value = value;
156157
}
157158
JS
158159
);
@@ -189,14 +190,6 @@ protected function renderHtml5RangeInput()
189190
{
190191
$html[] = Html::beginTag('div', ['class' => 'range-field']);
191192

192-
// workaround for: https://github.com/Dogfalo/materialize/issues/5761
193-
if (!isset($this->inputOptions['min'])) {
194-
$this->inputOptions['min'] = 0;
195-
}
196-
if (!isset($this->inputOptions['max'])) {
197-
$this->inputOptions['max'] = 100;
198-
}
199-
200193
if ($this->hasModel()) {
201194
$html[] = Html::activeInput('range', $this->model, $this->attribute, $this->inputOptions);
202195
} else {
@@ -253,7 +246,7 @@ protected function registerClientScripts()
253246
if ($this->clientOptions !== false) {
254247
$options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
255248
$view->registerJs(<<<JS
256-
var $varName = document.getElementById('$id');
249+
let $varName = document.getElementById('$id');
257250
noUiSlider.create($varName, {$options});
258251
JS
259252
);

0 commit comments

Comments
 (0)