Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 3f5c475

Browse files
committed
fix: set initial value if no value attribute is set
#183
1 parent 9c1b171 commit 3f5c475

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

dist/rangeslider.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@
279279
Plugin.prototype.init = function() {
280280
this.update(true, false);
281281

282-
// Set initial value just in case it is not set already.
283-
// Prevents trouble if we call `update(true)`
284-
this.$element[0].value = this.value;
285-
286282
if (this.onInit && typeof this.onInit === 'function') {
287283
this.onInit();
288284
}
@@ -294,7 +290,7 @@
294290
if (updateAttributes) {
295291
this.min = tryParseFloat(this.$element[0].getAttribute('min'), 0);
296292
this.max = tryParseFloat(this.$element[0].getAttribute('max'), 100);
297-
this.value = tryParseFloat(this.$element[0].value, this.min + (this.max-this.min)/2);
293+
this.value = tryParseFloat(this.$element[0].value, Math.round(this.min + (this.max-this.min)/2));
298294
this.step = tryParseFloat(this.$element[0].getAttribute('step'), 1);
299295
}
300296

@@ -433,7 +429,7 @@
433429
};
434430

435431
Plugin.prototype.setValue = function(value) {
436-
if (value === this.value) {
432+
if (value === this.value && this.$element[0].value !== '') {
437433
return;
438434
}
439435

dist/rangeslider.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rangeslider.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,6 @@
278278
Plugin.prototype.init = function() {
279279
this.update(true, false);
280280

281-
// Set initial value just in case it is not set already.
282-
// Prevents trouble if we call `update(true)`
283-
this.$element[0].value = this.value;
284-
285281
if (this.onInit && typeof this.onInit === 'function') {
286282
this.onInit();
287283
}
@@ -293,7 +289,7 @@
293289
if (updateAttributes) {
294290
this.min = tryParseFloat(this.$element[0].getAttribute('min'), 0);
295291
this.max = tryParseFloat(this.$element[0].getAttribute('max'), 100);
296-
this.value = tryParseFloat(this.$element[0].value, this.min + (this.max-this.min)/2);
292+
this.value = tryParseFloat(this.$element[0].value, Math.round(this.min + (this.max-this.min)/2));
297293
this.step = tryParseFloat(this.$element[0].getAttribute('step'), 1);
298294
}
299295

@@ -432,7 +428,7 @@
432428
};
433429

434430
Plugin.prototype.setValue = function(value) {
435-
if (value === this.value) {
431+
if (value === this.value && this.$element[0].value !== '') {
436432
return;
437433
}
438434

0 commit comments

Comments
 (0)