Reputation: 116
I have a Backbone model which has a title attribute. In the validation function, it checks that the title is less than 40 characters.
On save on the server, it runs the title attribute through php's htmlentities function*. Then, we output the result of the save.
If the input contains any escapable characters, the output from htmlentities will be longer than the input. If this happens, and the new string is longer than 40 characters, the model on the client fails validation when it tries to parse the saved attributes. When this happens, neither of the success/failure callbacks are called. This makes it look like the page has hung.
In the ideal solution, I would like this to call the success callback and just ignore the failure (because the 40 characters is more of a soft limit). If this is impossible I would like it to at least call the failure callback.
Does anyone know how to accomplish this?
Thanks! --Connor
*Yes, I know it's generally considered bad practice to save escaped data, but backwards compatibility.
Upvotes: 1
Views: 72
Reputation: 17168
The options you pass to save()
get passed along to sync()
which then get passed along to set()
which then get passed to _validate()
which will always return true if the options passed to it have validate
set to false. Try this:
model.save(null, { validate: false })
Upvotes: 1