I have a web app that allows users to submit and save HTML. The user types in the html s/he wants to use into several different fields. Some are text input elements and some are textarea elements. When the user submits their markup I convert the special characters into html entities.
When the user comes back to edit the html they submitted I fetch their entries from the data base and prepopulate the form using knockout. In order to display the html as they typed it, I call a function on any data that being bound to my view model to remove change any entities back into ampersands and brackets and all that fun stuff.
var viewModel = {
property : ko.observable(decode_entities(varContainingUserInput)),
....
}
I know when binding to most html elements like divs or p tags, you can use knockouts html binding to decode entities before you print them. This alleviates the need to call the decode_entities function. However this doesn't work with input fields.
I want to get rid of the decode_entities function, or roll it into knockout so it's not scattered all throughout my code. I would like to get knockout to just decode entities in my bindings with any extra work.