Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout fires change event when select list initializing
    primarykey
    data
    text
    <p>I'm having a issue with knockout select list binding, My problem is I'm having a list of items, that contains description,key and editable. using the list of items I'm populating the select box.</p> <pre><code> var RequiredItemLine = function () { var self = this; self.desc = ko.observable(); self.key = ko.observable(); self.editable = ko.observable(false); self.requireditemsdata = ko.observableArray([ { desc: "Boarding of exposed wall openings in the vicinity of ...", key: "233", editable: true }, { desc: "Call in manufacturers to initiate repairs on ...", key: "242", editable: true }, { desc: "Call in specialist restorers/recoverers for ...", key: "244", editable: true }, { desc: "Dispatch items for repair (schedule enclosed)", key: "243", editable: false }, { desc: "Drying and cleaning of contents comprising ...", key: "240", editable: true }, { desc: "Drying and protective oiling of water affected equipment", key: "241", editable: false }, { desc: "Drying out of the affected areas of the premises", key: "235", editable: false }, { desc: "Removal and repackaging of stock comprising ...", key: "239", editable: true }, { desc: "Removal of agreed vulnerable contents to a place of safety (schedule enclosed) ", key: "236", editable: false }, { desc: "Segregation of affected and unaffected stock comprising ...", key: "238", editable: true }, { desc: "Temporary covering of roof to reinstate water tight integrity ", key: "234", editable: false }, { desc: "Temporary guarding of affected area", key: "237", editable: false }, { desc: "Temporary shoring of affected structure", key: "232", editable: false }]); self.selectedItem = ko.observableArray([]); self.selectedItem.subscribe(function (newValue) { if (newValue) { self.editable(newValue.editable); //alert(newValue.editable); } }); } </code></pre> <p>whenever the user select an options from the select list, it contains the property editable,then the select list has to hide from the DOM and text box has to be visible to DOM and the value has to assigned from the selected desc from the select list.</p> <pre><code> var RequiredItems = function () { var self = this; self.requiredItemSelection = ko.observableArray([]); self.addRequiredItem = function () { self.requiredItemSelection.push(new RequiredItemLine()); }; self.removeRequiredItem = function (line) { self.requiredItemSelection.remove(line); }; } var vm = new RequiredItems(); ko.applyBindings(vm); </code></pre> <p>the problem is whenever the select is loading to the DOM change event is firing and display the select list or the input field. </p> <pre><code> &lt;div class='liveExample' &gt; &lt;button data-bind='click: addRequiredItem'&gt;Add Required Item&lt;/button&gt; &lt;hr /&gt; &lt;table width='100%'&gt; &lt;tbody data-bind='foreach: requiredItemSelection' &gt; &lt;tr&gt; &lt;td &gt; &lt;select data-bind='options: requireditemsdata, optionsText: "desc", value: selectedItem'&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;a href='#' data-bind='click: $parent.removeRequiredItem'&gt; &lt;img src="../images/Close.gif" /&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr data-bind="visible : selectedItem().editable"&gt; &lt;td&gt; &lt;div class="editablecontent" data-bind='html : selectedItem().desc.replace(/\.\.\./g, "&lt;span style=&amp;#39;background-color:#ff77ee;margin-left:-2px;letter-spacing:0.05em&amp;#39; contenteditable &gt;...&lt;/span&gt;")'&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;ul data-bind='foreach: requiredItemSelection'&gt; &lt;li data-bind="text : selectedItem().desc "&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>see the fiddle <a href="http://jsfiddle.net/aroor/VFv4H/3/">http://jsfiddle.net/aroor/VFv4H/3/</a> Note: I dont want to use the optionsCaption binding. is there any way to solve this issue? Or didn't i declare the data structure properly ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload