Dogfalo/materialize · error · Error
noUiSlider: 'behaviour' must be a string containing options.
Error message
noUiSlider: 'behaviour' must be a string containing options.
What it means
noUiSlider requires the 'behaviour' option to be a string of space-or-comma separated keywords (tap, drag, fixed, snap, hover). The guard rejects any non-string before parsing keywords, because indexOf would otherwise throw or misbehave.
Source
Thrown at extras/noUiSlider/nouislider.js:670
// Invert connection for RTL sliders, so that the proper
// handles get the connect/background classes.
switch ( entry ) {
case 'ltr':
parsed.dir = 0;
break;
case 'rtl':
parsed.dir = 1;
break;
default:
throw new Error("noUiSlider: 'direction' option was not recognized.");
}
}
function testBehaviour ( parsed, entry ) {
// Make sure the input is a string.
if ( typeof entry !== 'string' ) {
throw new Error("noUiSlider: 'behaviour' must be a string containing options.");
}
// Check if the string contains any keywords.
// None are required.
var tap = entry.indexOf('tap') >= 0;
var drag = entry.indexOf('drag') >= 0;
var fixed = entry.indexOf('fixed') >= 0;
var snap = entry.indexOf('snap') >= 0;
var hover = entry.indexOf('hover') >= 0;
if ( fixed ) {
if ( parsed.handles !== 2 ) {
throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles");
}
// Use margin to enforce fixed state
testMargin(parsed, parsed.start[1] - parsed.start[0]);View on GitHub (pinned to 824e78248b)
Solutions
- Pass behaviour as a single string containing the desired flags, e.g. 'tap drag' or 'drag-tap'.
- If you have an array of flags, join them: behaviour: flags.join(' ').
- Omit behaviour to use the default, or set it to an empty string '' if no flags are wanted.
Example fix
// before
noUiSlider.create(el, { start: 0, range:{min:0,max:100}, behaviour: ['tap','drag'] });
// after
noUiSlider.create(el, { start: 0, range:{min:0,max:100}, behaviour: 'tap drag' }); Defensive patterns
Strategy: validation
Validate before calling
function normalizeBehaviour(raw) {
if (Array.isArray(raw)) return raw.join(' ');
if (typeof raw !== 'string') throw new TypeError('behaviour must be a string');
return raw;
} Type guard
function isValidBehaviour(v) { return typeof v === 'string'; } Prevention
- Treat behaviour as a single space-separated string, not an array.
- If accepting user input, validate with typeof === 'string' before create().
- Document the allowed keywords (tap, drag, fixed, snap, hover) next to the config.
When it happens
Trigger: Call noUiSlider.create() with options.behaviour that is not a string: a boolean true, an array ['tap','drag'], an object, undefined-coerced, or null.
Common situations: Developers pass an array thinking behaviour accepts multiple flags as a list, or pass true/false expecting a boolean toggle. Also happens when behaviour is loaded from JSON where it was serialized as an array.
Related errors
- noUiSlider: 'padding' option must be less than half the rang
- noUiSlider: 'direction' option was not recognized.
- noUiSlider: 'fixed' behaviour must be used with 2 handles
- noUiSlider: must pass a formatter for all handles.
- noUiSlider: 'tooltips' must be passed a formatter or 'false'
AI-assisted analysis of Dogfalo/materialize@824e78248b (2026-08-13).
Data as JSON: /api/errors/c7ff1e24a8008439.
Report an issue: GitHub.