0
votes

I've coded a form with various value-bindings and a knockout viewmodel behind it. The form is submitted by an AJAX post (triggered by a click-binding on a form button). I've noticed that the model isn't correctly updated BEFORE the post when I make changes in a textfield, leave the cursor in it and directly click the submit button.

I'm aware of the "afterkeydown" option of the value binding, but I prefer not to use it, since it would also trigger my validation on every key strike. Is there a way to force the model update programmatically in my ajax submit function?

1
Can you throw it in a fiddle so we can see your code. It's hard to say what you are doing wrong without that.Kyeotic

1 Answers

1
votes

Try using the submit binding instead of click:

<form data-bind="submit: doSomething">
    ... form contents go here ...
    <button type="submit">Submit</button>
</div>

<script type="text/javascript">
    var viewModel = {
        doSomething : function(formElement) {
            // ... now do something 
        }
    };
</script>

The documentation page on submit: http://knockoutjs.com/documentation/submit-binding.html