Skip to content

Commit 592bcc0

Browse files
committed
Merge branch 'master' into feature/opt-in-widget
2 parents 19e7074 + 732e12a commit 592bcc0

31 files changed

+76
-23
lines changed

src/editor.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AbstractEditor {
1717
this.active = true
1818
this.isUiOnly = false
1919
this.options = extend({}, (this.options || {}), (this.schema.options || {}), (options.schema.options || {}), options)
20-
this.enforceConst = this.options.enforce_const ?? this.jsoneditor.options.enforce_const
20+
this.enforceConstEnabled = this.options.enforce_const ?? this.jsoneditor.options.enforce_const
2121
this.formname = this.jsoneditor.options.form_name_root || 'root'
2222

2323
if (!options.path && !this.schema.id) this.schema.id = this.formname
@@ -273,7 +273,7 @@ export class AbstractEditor {
273273
this.theme.visuallyHidden(this.header)
274274
}
275275

276-
if (this.enforceConst && this.schema.const) {
276+
if (this.enforceConstEnabled && this.schema.const) {
277277
this.disable()
278278
}
279279
}
@@ -585,9 +585,18 @@ export class AbstractEditor {
585585
}
586586

587587
setValue (value) {
588+
value = this.applyConstFilter(value)
588589
this.value = value
589590
}
590591

592+
applyConstFilter (value) {
593+
if (this.enforceConstEnabled && typeof this.schema.const !== 'undefined') {
594+
value = this.schema.const
595+
}
596+
597+
return value
598+
}
599+
591600
getValue () {
592601
if (!this.dependenciesFulfilled) {
593602
return undefined
@@ -629,7 +638,7 @@ export class AbstractEditor {
629638
}
630639

631640
getDefault () {
632-
if (this.enforceConst && this.schema.const) {
641+
if (this.enforceConstEnabled && this.schema.const) {
633642
return this.schema.const
634643
}
635644

src/editors/ace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { extend } from '../utilities.js'
33

44
export class AceEditor extends StringEditor {
55
setValue (value, initial, fromTemplate) {
6+
value = this.applyConstFilter(value)
67
const res = super.setValue(value, initial, fromTemplate)
78
if (res !== undefined && res.changed && this.ace_editor_instance) {
89
this.ace_editor_instance.setValue(res.value)

src/editors/array.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export class ArrayEditor extends AbstractEditor {
348348
}
349349

350350
setValue (value = [], initial) {
351+
value = this.applyConstFilter(value)
351352
/* Make sure value has between minItems and maxItems items in it */
352353
value = this.ensureArraySize(value)
353354

src/editors/array/choices.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { extend } from '../../utilities.js'
44
export class ArrayChoicesEditor extends MultiSelectEditor {
55
setValue (value, initial) {
66
if (this.choices_instance) {
7+
value = this.applyConstFilter(value)
78
/* Make sure we are dealing with an array of strings so we can check for strict equality */
89
value = [].concat(value).map(e => `${e}`)
910

src/editors/array/select2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { extend, hasOwnProperty } from '../../utilities.js'
33

44
export class ArraySelect2Editor extends MultiSelectEditor {
55
setValue (value, initial) {
6+
value = this.applyConstFilter(value)
7+
68
if (this.select2_instance) {
79
/* Make sure we are dealing with an array of strings so we can check for strict equality */
810
value = [].concat(value).map(e => `${e}`)

src/editors/array/selectize.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { extend } from '../../utilities.js'
33

44
export class ArraySelectizeEditor extends MultiSelectEditor {
55
setValue (value, initial) {
6+
value = this.applyConstFilter(value)
7+
68
if (this.selectize_instance) {
79
/* Make sure we are dealing with an array of strings so we can check for strict equality */
810
value = [].concat(value).map(e => `${e}`)

src/editors/base64.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export class Base64Editor extends AbstractEditor {
149149
}
150150

151151
setValue (val) {
152+
val = this.applyConstFilter(val)
153+
152154
if (this.value !== val) {
153155
if (this.schema.readOnly && this.schema.enum && !this.schema.enum.includes(val)) this.value = this.schema.enum[0]
154156
else this.value = val

src/editors/checkbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AbstractEditor } from '../editor.js'
22

33
export class CheckboxEditor extends AbstractEditor {
44
setValue (value, initial) {
5+
value = this.applyConstFilter(value)
56
value = !!value
67
const changed = this.getValue() !== value
78
this.value = value

src/editors/choices.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import rules from './choices.css.js'
44

55
export class ChoicesEditor extends SelectEditor {
66
setValue (value, initial) {
7+
value = this.applyConstFilter(value)
8+
79
if (this.choices_instance) {
810
/* Sanitize value before setting it */
911
let sanitized = this.typecast(value || '')

src/editors/colorpicker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class ColorEditor extends StringEditor {
1717
}
1818

1919
setValue (value, initial, fromTemplate) {
20+
value = this.applyConstFilter(value)
21+
2022
const res = super.setValue(value, initial, fromTemplate)
2123
if (this.picker_instance && this.picker_instance.domElement && res && res.changed) {
2224
this.picker_instance.setColor(res.value, true)

0 commit comments

Comments
 (0)