0
votes

The below code tries to bind observable properties of a model to template. While running the application, the data on the radio button is displayed perfectly but when clicked does not changes the models property values.

<script type="text/html" id="RadioButton">
        <input type = "radio" data-bind = "attr: {'name': ko.computed(function() { return $parents[0].QuestionID().toString(); }), 'value': ko.computed(function() { return $parents[0].OptionStatement().toString(); }) }, checked: $parents[1].Answer_RadioList().TextResponse() "/>
        <span data-bind = "text: $parents[1].Answer_RadioList().TextResponse()"></span>
</script>

The model to the application looks like this:


    function QuestionList(T)
    {
        this.QuestionID = ko.observable(T.QuestionID);
        this.Question = ko.observable(T.Question);
        this.SurveyID = ko.observable(T.SurveyID);
        this.CategoryID = ko.observable(T.CategoryID);
        this.SubCategoryID = ko.observable(T.SubCategoryID);
        this.ParentID = ko.observable(T.ParentID);
        this.IsMandatory = ko.observable(T.IsMandatory);
        this.IsARadioButtonControl = ko.observable(T.IsARadioButtonControl);
        if (T.Answer_RadioList)
        {
            this.Answer_RadioList = ko.observable(new Answer_RadioList(T.Answer_RadioList));
        }
        this.HasInternalControls = ko.observable(T.HasInternalControls);
        this.InternalControlTypeID = ko.observable(T.InternalControlTypeID);
        this.OptionListCollection = ko.observableArray([]);
        this.InternalQuestionListCollection = ko.observableArray([]);
    }

    function OptionList(T)
    {
        this.OptionID = ko.observable(T.OptionID);
        this.OptionStatement = ko.observable(T.OptionStatement);
        this.QuestionID = ko.observable(T.QuestionID);
        this.IsMandatory = ko.observable(T.IsMandatory);
        this.IsTabularControl = ko.observable(T.IsTabularControl);
        this.ControlTypeID = ko.observable(T.ControlTypeID);
        this.ControlList = ko.observable(new ControlList(T.ControlList));
        this.TabularControl = ko.observableArray([]);
        this.AxisSummation = ko.observable(new AxisSummation(T.AxisSummation));
        this.IsADropDownList = ko.observable(T.IsADropDownList);
        this.Answer_OptionList = ko.observable(new Answer_OptionList(T.Answer_OptionList));
    }

    function Answer_RadioList(T)
    {
        this.Answer_RadioListID = ko.observable(T.Answer_RadioListID);
        this.QuestionID = ko.observable(T.QuestionID);
        this.TextResponse = ko.observable(T.TextResponse);
    }

1

1 Answers

1
votes

You need to remove the parenthesis in checked: $parents[1].Answer_RadioList().TextResponse():

checked: $parents[1].Answer_RadioList().TextResponse

Otherwise you give a value instead of an observable.

Check this simple fiddle