* Loads a given form by deserializing given data, optionally with given special value handling functions. * * @param {HTMLFormElement} form The form to deserialize data into. * @param {Object} data The data object to deserialize into the form. * @param {Object}
(form, data, options)
| 198 | * is excluded if the function returns true. |
| 199 | */ |
| 200 | function deserialize(form, data, options) { |
| 201 | let defaults = { |
| 202 | valueFunctions: null, |
| 203 | include: [], |
| 204 | exclude: [], |
| 205 | includeFilter: null, |
| 206 | excludeFilter: null |
| 207 | } |
| 208 | let config = Object.assign({}, defaults, options) |
| 209 | // apply given value functions first |
| 210 | let speciallyHandled = [] |
| 211 | if (config.valueFunctions !== null) { |
| 212 | speciallyHandled = applySpecialHandlers(data, form, config) |
| 213 | } |
| 214 | // fill remaining values normally |
| 215 | for (let name in data) { |
| 216 | if (isNameFiltered(name, config.include, config.exclude)) { |
| 217 | continue |
| 218 | } |
| 219 | if (!speciallyHandled.includes(name)) { |
| 220 | let inputs = [...form.elements].filter(element => element.name === name |
| 221 | && !isElementFiltered(element, config.includeFilter, config.excludeFilter)) |
| 222 | inputs.forEach((input, i) => { |
| 223 | applyValues(input, data[name], i) |
| 224 | }) |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Loads a given form from local or session storage, optionally with given special value handling functions. |
no test coverage detected