(value, initial, fromTemplate)
| 18 | } |
| 19 | |
| 20 | setValue (value, initial, fromTemplate) { |
| 21 | value = this.purify(value) |
| 22 | value = this.applyConstFilter(value) |
| 23 | |
| 24 | if (this.template && !fromTemplate) return |
| 25 | |
| 26 | if (!this.shouldBeUnset() && (value === null || typeof value === 'undefined')) value = '' |
| 27 | else if (typeof value === 'object') value = JSON.stringify(value) |
| 28 | else if (!this.shouldBeUnset() && (typeof value !== 'string')) value = `${value}` |
| 29 | |
| 30 | if (value === this.serialized) return |
| 31 | |
| 32 | /* Sanitize value before setting it */ |
| 33 | const sanitized = this.sanitize(value) |
| 34 | |
| 35 | if (this.input.value === sanitized) return |
| 36 | |
| 37 | this.setValueToInputField(sanitized) |
| 38 | |
| 39 | if (this.format === 'range') { |
| 40 | const output = this.control.querySelector('output') |
| 41 | if (output) { |
| 42 | output.value = sanitized |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | const changed = fromTemplate || this.getValue() !== value |
| 47 | |
| 48 | this.refreshValue() |
| 49 | |
| 50 | if (initial) this.is_dirty = false |
| 51 | else if (this.jsoneditor.options.show_errors === 'change') this.is_dirty = true |
| 52 | |
| 53 | if (this.adjust_height) this.adjust_height(this.input) |
| 54 | |
| 55 | /* Bubble this setValue to parents if the value changed */ |
| 56 | if (changed) { |
| 57 | this.onChange(true, fromTemplate) |
| 58 | } |
| 59 | |
| 60 | /* Return object with changed state and sanitized value for use in editors that extend this */ |
| 61 | return { changed, value: sanitized } |
| 62 | } |
| 63 | |
| 64 | setValueToInputField (value) { |
| 65 | this.input.value = value === undefined ? '' : value |
no test coverage detected