Use toFixed instead of toPrecision in Range input

toPrecision returns an exponential notation for example for:
 const x = 100
 x.toPrecision(2)
This commit is contained in:
Yohan Boniface 2023-10-05 15:14:28 +02:00
parent d0b01e774c
commit 20cdc837af

View file

@ -854,10 +854,10 @@ L.FormBuilder.Range = L.FormBuilder.Input.extend({
datalist.id = `range-${this.options.label || this.name}`
this.input.setAttribute('list', datalist.id)
let options = ''
const step = this.options.step || 1,
digits = step < 1 ? 2 : 0
for (let i = this.options.min; i <= this.options.max; i += this.options.step) {
options += `<option value="${i.toPrecision(2)}" label="${i.toPrecision(
2
)}"></option>`
options += `<option value="${i.toFixed(digits)}" label="${i.toFixed(digits)}"></option>`
}
datalist.innerHTML = options
},