IE8 Throws "This Command Not Supported" Error When Using Knockout to Bind Data Using Attr Type

The code: -

<html> <head> <script type="text/javascript" src="http://knockoutjs.com/downloads/knockout-2.3.0.js"></script> </head> <body> <table> <thead> <tr> <th>Name</th> <th>InputType</th> </tr> </thead> <tbody data-bind="foreach: settings"> <tr> <td data-bind="text: name"></td> <td><input data-bind="attr: {type: dtype}"/></td> </tr> </tbody> </table> <script type="text/javascript"> var viewModel = function(){ this.settings = ko.observableArray([{name: "Bungle",dtype:"text"},{name: "George",dtype: "checkbox"},{name: "Zippy",dtype:"text"}]); }; ko.applyBindings(new viewModel()); </script> </body> </html> 

The above code is also written in the http://jsfiddle.net/uByVQ/ script. Although the script recorded in the fiddle works fine in Chrome, it does not work properly in IE8. I get an error

"This command is not supported."

I am using knockout 2.3

Can someone point me to a job?

Thanks.

+2
source share
1 answer

It looks like in IE you cannot change the type of an input element after it is added to the DOM.

The type property is read / write-once, but only when an input element is created using the createElement method and before it is added to the document.

http://msdn.microsoft.com/en-us/library/ms534700.aspx

There are some ugly problems associated with creating a new element and deleting an existing one, but for this you will need to write a custom mediation knockout.

You could get around it with if binding :

 <tr> <td data-bind="text: name"></td> <td> <span data-bind="if: dtype=='checkbox'"><input type='checkbox' /></span> <span data-bind="if: dtype=='text'"><input type='text' /></span> </td> </tr> 

See: http://jsfiddle.net/GQEs5/

But it is really unsatisfactory and verbose.

I would also add that it is philosophically unclean to have presentation details in your model, but I definitely recognize the pragmatic advantages of your approach.

+5
source

Source: https://habr.com/ru/post/1410765/


All Articles