Function to create bindings between Dojo / Dijit widgets and knockout js observables
It is a function to bind Dojo/Dijit widgets with Knockout JS observables. Accepts "options" objects with following list of fields:
dijit.byId("someId")
Either element, elementId or elements parameter is required
viewModel.someValue
js::
var viewModel = {
firstName: ko.observable()
};
html::
<input type="text" name="firstName" data-dojo-type="dijit.form.TextBox" id="firstName">
binding::
bindDojoAndKnockout({element: dijit.byId('firstName'), observable: viewModel.firstName});
The only difference is that elementAttribute we'd like to get value of is "checked"
js::
var viewModel = {
agree: ko.observable()
};
html::
<input type="checkbox" name="agree" data-dojo-type="dijit.form.CheckBox" id="agree">
binding::
bindDojoAndKnockout({elementId: 'agree', elementAttribute: 'checked', observable: viewModel.agree});
Radio buttons are special case
elements
attributejs::
var viewModel {
drink: ko.observable()
}
html::
<label>
<input type="radio" name="drink" dojoType="dijit.form.RadioButton" value="coffee" id="coffeeButton"> Coffee
</label>
<label>
<input type="radio" name="drink" dojoType="dijit.form.RadioButton" value="tea" id="teaButton"> Tea
</label>
binding::
bindDojoAndKnockout({elements: 'input[type=radio]', observable: viewModel.drink})