MCPcopy Create free account
hub / github.com/FThompson/FormPersistence.js / deserialize

Function deserialize

form-persistence.js:200–227  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 1

loadFunction · 0.85

Calls 4

applySpecialHandlersFunction · 0.85
isNameFilteredFunction · 0.85
isElementFilteredFunction · 0.85
applyValuesFunction · 0.85

Tested by

no test coverage detected