3

I have a knockout viewModel that includes several arrays of variable size that is eventually submitted ala

ko.utils.postJson(location.href, { viewModel: ko.mapping.toJS(this) });

I have a Json model binder server side that depends on the names of the properties being the same. After looking at the implementation of ko.utils.postJson, I determined that the problem lies with setting the value property of an input element in some browsers (notably Chrome).

Here is a JSFiddle to illustrate the problem.

I'm considering just using ajax to submit the viewModel and then returning a url that I would redirect to in the success handler, client side, but that seems smelly. What is the best practice for this sort of thing? Are there any alternative solutions that might be better?

kmkemp
  • 1,656
  • 3
  • 18
  • 21
  • Two possibly relevant questions http://stackoverflow.com/questions/3107999/how-many-characters-are-possible-in-an-input-field-in-html and http://stackoverflow.com/questions/1262376/is-there-a-limit-on-how-much-json-can-hold ... based on your jsFiddle. Did you resolve this? How about using a `textarea` instead of an input field? – artlung Dec 11 '13 at 22:28
  • I decided to submit asynchronously and redirect based on the result, as described in my question. – kmkemp Dec 12 '13 at 20:03
  • 1
    I suggest putting in your solution and explanation as an answer to close out the question. – artlung Dec 17 '13 at 18:08
  • While it "fixed" my issue, I'm not convinced it's a good solution, and the entire purpose of my question was to try and get alternatives that might be better. – kmkemp Dec 19 '13 at 15:33

1 Answers1

1

This issue has been reported on Knockout's GitHub repo: https://github.com/knockout/knockout/issues/1252 and https://github.com/knockout/knockout/pull/1297

It's scheduled to be fixed in the next version of Knockout, but you can take a look at the two issues to see how you could work around the problem for now.

Michael Best
  • 16,623
  • 1
  • 37
  • 70