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

Function applyValues

form-persistence.js:288–310  ·  view source on GitHub ↗

* Applies the given values to the given element. * Adds any checkbox elements checked to the given array. * * @param {HTMLElement} element The element to apply values to. * @param {Array} values The array of values. Some element types use the first element instead of the

(element, values, index)

Source from the content-addressed store, hash-verified

286 * @param {Array} checkedBoxes The array of checkboxes to add any clicked checkboxes to.
287 */
288 function applyValues(element, values, index) {
289 let tag = element.tagName
290 if (tag === 'INPUT') {
291 let type = element.type
292 if (type === 'radio') {
293 element.checked = (element.value === values[0])
294 } else if (type === 'checkbox') {
295 element.checked = values[index]
296 } else {
297 element.value = values[index]
298 }
299 } else if (tag === 'TEXTAREA') {
300 element.value = values[index]
301 } else if (tag === 'SELECT') {
302 if (element.multiple) {
303 for (let option of element.options) {
304 option.selected = values.includes(option.value)
305 }
306 } else {
307 element.value = values[index]
308 }
309 }
310 }
311
312 /**
313 * Runs given value handling functions in place of basic value insertion.

Callers 1

deserializeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected