Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to read the 'selectionStart' property from 'HTMLInputElement':

I'm using binding handler.if i remove this code my code is saved.but if i use this code it will throw error.

Uncaught InvalidStateError: Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('checkbox') does not support selection.

 ko.bindingHandlers.wysiwyg = {
        init: function (element, valueAccessor, allBindingsAccessor) {
            debugger;
            var options = allBindingsAccessor().wysiwygOptions || {};
            var value = ko.utils.unwrapObservable(valueAccessor());

                    //value = value.text();
            //var v = value[0].childNodes[0].data;
            var $e = $(element);

            $.extend(true, {
                initialContent: value
            }, options);

            $e.wysiwyg(options);

            //handle the field changing
            function detectFn() {
                var observable = valueAccessor();
                var newvalue = $e.wysiwyg("getContent");
                observable(newvalue);
            }

            var current = $e.wysiwyg('document');
            var timer;
            current.bind({
                keyup: function () {
                    clearTimeout(timer);
                    timer = setTimeout(detectFn, 1000);
                }
            });

            //handle disposal (if KO removes by the template binding)
            ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
                $e.wysiwyg('destroy');
            });


        },
        update: function (element, valueAccessor) {
            var value = ko.utils.unwrapObservable(valueAccessor());

            $(element).wysiwyg("setContent", value);
            ko.bindingHandlers.value.update(element, valueAccessor);
        }
    };
like image 537
diy Avatar asked Sep 26 '22 01:09

diy


1 Answers

You have an input element of type="checkbox" in your HTML, where the Javascript code expects a type="text".

A checkbox has no text, thus it cannot have any selection. But your code tries to access the non-existent property selectionStart.

Please have a look at https://jsfiddle.net/u99f0q1j/ to see the issue demonstrated.

As you did not post your HTML, it is hard to see what is causing the error.

But in your browser dev tools, you should be able to click on the line number next to your "Uncaught InvalidStateError" message in order to see the Javascript line that tried to access the selectionStart property on your checkbox.

like image 187
pixelistik Avatar answered Oct 31 '22 00:10

pixelistik