0

Hello I would like to do create a simpledropdownlist, we are using MVC architecture with SQL server. On frontend side, we are using typescript with knockout.

I need to do adjustment to existing form. The adjustment is very simple. I need to add dropdown list with 3 values - "Not chosen", "Yes", "No".

The property in model is of type bool?. Initial value should be "Not chosen" and if user saves the form with this value "null" should be saved to the DB.

I made this:

<select id="selectForTaxPurposes"
        data-bind="booleanValue: $data.model.forTaxPurposes,
    <option id="nothing" value="null">Choose</option>
    <option id="yes" value="true">Yes</option>
    <option id="no" value="false">Ne</option>
</select>¨

But the form won't even load. Does anybody have any advise on this? I found couple of solutions, but they are very complicated for this case

xcelm
  • 541
  • 1
  • 6
  • 19
  • If you use developer tools, for Chrome press F12 and they will show up, you should normally see some kind of error there. Could you please add also this in your question ? Thanks – Christos Aug 02 '19 at 12:41
  • 1
    @Christos - forgot to do so - knockout-3.4.2.js:3391 Uncaught TypeError: Unable to process binding "booleanValue: function(){return $data.model.danove_uznatelne }" Message: Cannot read property 'toString' of null at read (koutil.ts:1041) at Function.evaluateImmediate_CallReadThenEndDependencyDetection (knockout-3.4.2.js:2183) at Function.evaluateImmediate_CallReadWithDependencyDetection (knockout-3.4.2.js:2150) at Function.evaluateImmediate (knockout-3.4.2.js:2111) at Object.ko.computed.ko.dependentObservable (knockout-3.4.2.js:1964) at init (koutil.ts:1039)... – xcelm Aug 02 '19 at 12:42
  • check this link https://stackoverflow.com/questions/10510683/knockoutjs-version-2-1-0-bind-boolean-value-to-select-box – mukhtar alam Aug 02 '19 at 13:00
  • You'll have to show the code for your `booleanValue` custom binding. – Jason Spake Aug 02 '19 at 16:24

1 Answers1

0

instead of using booleanValue use value as binding. Also please check the link that I have posted. Knockoutjs (version 2.1.0): bind boolean value to select box

Also it would be better If you provide your model for the code aswell.

mukhtar alam
  • 195
  • 1
  • 12