{"record":{"id":"d2060d697c7bf260","repo":"nosir/cleave.js","slug":"the-input-element-type-does-not-support-selection","errorCode":null,"errorMessage":"The input element type does not support selection","messagePattern":"The input element type does not support selection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/utils/Util.js","lineNumber":238,"sourceCode":"            return;\n        }\n\n        // cursor is already in the end\n        if (element && element.value.length <= position) {\n          return;\n        }\n\n        if (element.createTextRange) {\n            var range = element.createTextRange();\n\n            range.move('character', position);\n            range.select();\n        } else {\n            try {\n                element.setSelectionRange(position, position);\n            } catch (e) {\n                // eslint-disable-next-line\n                console.warn('The input element type does not support selection');\n            }\n        }\n    },\n\n    getActiveElement: function(parent) {\n        var activeElement = parent.activeElement;\n        if (activeElement && activeElement.shadowRoot) {\n            return this.getActiveElement(activeElement.shadowRoot);\n        }\n        return activeElement;\n    },\n\n    isAndroid: function () {\n        return navigator && /android/i.test(navigator.userAgent);\n    },\n\n    // On Android chrome, the keyup and keydown events\n    // always return key code 229 as a composition that","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/nosir/cleave.js/blob/a966c95cf5193f223485a10eec8405bb32b8f6dd/src/utils/Util.js#L220-L256","documentation":"Util.js wraps setSelectionRange in try/catch because some input types (email, number, and non-input elements) do not support programmatic caret positioning. When the browser rejects the call, Cleave warns instead of crashing at src/utils/Util.js:238; cursor restore is silently skipped.","triggerScenarios":"Applying a Cleave formatting option to <input type=\"number\">, type=\"email\", type=\"date\", or a non-input element; any keystroke path that tries to restore the caret position on such an element.","commonSituations":"Using type=\"number\" for credit cards or phone numbers (a common pattern that also breaks formatting); attaching Cleave to a contenteditable or div by mistake; browser differences (Firefox historically threw more eagerly than Chrome).","solutions":["Change the input to type=\"text\" (use inputmode=\"numeric\" to keep the numeric mobile keyboard).","Remove the Cleave formatter from unsupported input types.","Ignore the warning if degraded caret behavior is acceptable."],"exampleFix":"// before\n<input type=\"number\" class=\"card-input\" />\n// after\n<input type=\"text\" inputmode=\"numeric\" class=\"card-input\" />","handlingStrategy":"fallback","validationCode":"function supportsSelection(el) {\n  return el && typeof el.setSelectionRange === 'function' &&\n    !/^(number|email|date)$/.test(el.getAttribute('type') || '');\n}","typeGuard":"function isSelectableInput(el) {\n  return el instanceof HTMLInputElement &&\n    el.type === 'text';\n}","tryCatchPattern":"try {\n  el.setSelectionRange(pos, pos);\n} catch (e) {\n  console.warn('Element type ' + el.type + ' does not support selection; caret restore skipped');\n}","preventionTips":["Use type=\"text\" with inputmode=\"numeric\" for formatted numeric fields.","Never apply Cleave to type=\"number\", \"email\", or \"date\" inputs.","Expect degraded caret behavior on unsupported types — format on blur instead if needed.","Test on Firefox as well as Chromium, since selection support differs."],"tags":["dom","input-type","caret","selection"],"backgroundTag":"unsupported-input-type","analyzedSha":"a966c95cf5193f223485a10eec8405bb32b8f6dd","analyzedAt":"2026-09-02T23:44:35.488Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}