I have the below HTML and JS and I am using MVC. Here is the scenario
When the "Filter" object parameters are passed in to the HTML I am unable to assign the date field from the KO "optionsAfterRender" function.
HTML (Razor View):
var Filter =(Project.Models.Entity) ViewData["Filter"];
@if (Filter != null)
{
<div id="sdate">
<label>From Senior Date</label>
<input id="sdateVal" type="date" data-bind="value:SeniorDate,optionsAfterRender:function(){setOptionSrDate(@Filter.DateSenior.Value.ToString("yyyy-MM-dd"));}">
</div>
<div id="jdate">
<label>To Junior Date</label>
<input id="jdateVal" type="date" data-bind="value:JuniorDate,optionsAfterRender:function(){setOptionJrDate(@Filter.DateJunior.Value.ToString("yyyy-MM-dd"));}">
</div>
}
JS (Knockout):
self.setOptionSrDate = function (x) {//Sr Date
$("#sdateVal").val(x);//this does not assign the value
self.SeniorDate(x);//this does not assign the value
};