I am trying to get the all form fields when user submits the form, the problem is with checkbox field that is when the checkbox is checked the name is submit to server but if this is unchecked then the checkbox is not submit to server, I am using knockout latest version Here is my working code:
<form data-bind="submit: submitForm">
<input type="checkbox" name="checkboxTest" data-bind="checked : value" />
<input type="text" name="textTest" value="Test" />
<button type="submit"> Submit</button>
</form>
And here is my ViewModel:
function viewModel(data)
{
self.value = ko.observable(true);
// when user submit the form
self.submitForm = function(fields)
{
var dataparams = $(fields).serialize();
// The form fields name are showing here
console.log(dataparams);
}
}
ko.applyBindings(new viewModel);
Could anyone tell me how to get the checkbox even if that is unchecked using knockoutjs, thank you in advance.
Aucun commentaire:
Enregistrer un commentaire