Dogfalo/materialize · error · Error
noUiSlider: 'snap' option must be a boolean.
Error message
noUiSlider: 'snap' option must be a boolean.
What it means
Thrown by testSnap when 'snap' is not typeof === 'boolean'. snap forces handles onto the nearest step; the library refuses truthy/falsy coercions like 1/0 or the strings 'true'/'false'. Note the value is assigned to parsed.snap before the type check, but the throw still aborts initialization.
Source
Thrown at extras/noUiSlider/nouislider.js:518
if ( !Array.isArray( entry ) || !entry.length ) {
throw new Error("noUiSlider: 'start' option is incorrect.");
}
// Store the number of handles.
parsed.handles = entry.length;
// When the slider is initialized, the .val method will
// be called with the start options.
parsed.start = entry;
}
function testSnap ( parsed, entry ) {
// Enforce 100% stepping within subranges.
parsed.snap = entry;
if ( typeof entry !== 'boolean' ){
throw new Error("noUiSlider: 'snap' option must be a boolean.");
}
}
function testAnimate ( parsed, entry ) {
// Enforce 100% stepping within subranges.
parsed.animate = entry;
if ( typeof entry !== 'boolean' ){
throw new Error("noUiSlider: 'animate' option must be a boolean.");
}
}
function testAnimationDuration ( parsed, entry ) {
parsed.animationDuration = entry;
if ( typeof entry !== 'number' ){View on GitHub (pinned to 824e78248b)
Solutions
- Use the literal true or false.
- Coerce explicitly: snap: raw === true || raw === 'true'.
- Omit snap to keep the default (false).
Example fix
// before snap: el.dataset.snap // after snap: el.dataset.snap === 'true'
Defensive patterns
Strategy: type-guard
Validate before calling
if (opts.snap != null && typeof opts.snap !== 'boolean') {
throw new TypeError('snap must be a boolean');
} Type guard
function isBoolean(v) { return typeof v === 'boolean'; } Try / catch
try { noUiSlider.create(el, opts); }
catch (e) { if (/snap' option must be a boolean/.test(e.message)) { opts.snap = Boolean(opts.snap); /* retry */ } else throw e; } Prevention
- Bind checkboxes to their checked property, not their string value attribute.
- Coerce dataset strings: snap: raw === 'true'.
- Type the option as boolean in your config interface.
When it happens
Trigger: snap: 1, snap: 0, snap: 'true', or snap: 'false' (both strings are truthy and would also behave wrong if accepted).
Common situations: Reading snap from a checkbox's value attribute or dataset (always a string), from JSON like {"snap": 1}, or toggling it with a numeric flag.
Related errors
- noUiSlider: 'animate' option must be a boolean.
- noUiSlider: 'range' contains invalid value.
- noUiSlider: 'range' value isn't numeric.
- noUiSlider: 'limit', 'margin' and 'padding' must be divisibl
- noUiSlider: 'step' is not numeric.
AI-assisted analysis of Dogfalo/materialize@824e78248b (2026-08-13).
Data as JSON: /api/errors/b6599bbd6637920d.
Report an issue: GitHub.