Skip to content

Commit

Permalink
Merge branch 'master' into dev/fix-base64
Browse files Browse the repository at this point in the history
  • Loading branch information
gbisurgi committed Jul 3, 2023
2 parents dfbe53d + 4d48687 commit 1c0bee6
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Unreleased

- fixed issue #1364

### 2.10.1

- Added keep_only_existing_values option
Expand Down
2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export class AbstractEditor {
postBuild () {
this.setupWatchListeners()
this.addLinks()
this.register()
this.setValue(this.getDefault(), true)
this.updateHeaderText()
this.register()
this.onWatchedFieldChange()
}

Expand Down
3 changes: 3 additions & 0 deletions src/editors/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export class MultipleEditor extends AbstractEditor {
}

refreshValue () {
if (!this.editors[this.type]) {
return
}
this.value = this.editors[this.type].getValue()
}

Expand Down
1 change: 1 addition & 0 deletions src/editors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ export class ObjectEditor extends AbstractEditor {

Object.keys(this.editors).forEach(i => {
if (this.editors[i].isActive()) {
this.editors[i].refreshValue()
this.value[i] = this.editors[i].getValue()
}
})
Expand Down
3 changes: 3 additions & 0 deletions src/editors/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ export class StringEditor extends AbstractEditor {
}

refreshValue () {
if (!this.input) {
return
}
this.value = this.input.value
if (typeof this.value !== 'string' && !this.shouldBeUnset()) this.value = ''
this.serialized = this.value
Expand Down
13 changes: 13 additions & 0 deletions tests/codeceptjs/issues/issue-gh-1364_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* global Feature Scenario */

Feature('GitHub issue 1364')

Scenario('GitHub issue 1364 should remain fixed @issue-1364', ({ I }) => {
I.amOnPage('issues/issue-gh-1364.html')
I.waitForElement('.je-ready')
I.waitForValue('#value', '{"engine":"none","child1":{}}')
I.selectOption('[id="root[engine]"]', 'test1')
I.waitForValue('#value', '{"engine":"test1","child1":{"L2Name":""},"L1Name":""}')
I.selectOption('[id="root[engine]"]', 'none')
I.waitForValue('#value', '{"engine":"none","child1":{}}')
})
64 changes: 64 additions & 0 deletions tests/pages/issues/issue-gh-1364.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>GitHub Issue 1364</title>
<link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
<script src="../../../dist/jsoneditor.js"></script>
</head>
<body>
<div class="container">
<a href="https://github.com/json-editor/json-editor/issues/1158">GitHub Issue 1364</a>
<label for="value">Value</label>
<textarea class="form-control" id="value" rows="6" style="font-size: 12px; font-family: monospace;"></textarea>
<div id='editor_holder'></div>
</div>

<script>
var defaultSchema = {
"type": "object",
"properties": {
"engine": {
"type": "string",
"enum": ["none", "test1"]
},
"child1": {
"type": "object",
"properties": {
"L2Name": {
"type": "string",
"options": {
"dependencies": {
"root.engine": "test1"
}
}
}
}
},
"L1Name": {
"type": "string",
"options": {
"dependencies": {
"root.engine": "test1"
}
}
}
}
}

var value = document.querySelector('#value')
var editor = new JSONEditor(document.getElementById('editor_holder'),{
iconlib: 'fontawesome5',
object_layout: 'normal',
schema: defaultSchema,
show_errors: 'always',
theme: 'bootstrap4'
});

editor.on('change', function () {
value.value = JSON.stringify(editor.getValue())
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/pages/keep_only_existing_values.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="de">
<head>
<meta charset="utf-8"/>
<title>oneOf</title>
<title>keep_only_existing_values</title>
<link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
<script src="../../dist/jsoneditor.js"></script>
Expand Down

0 comments on commit 1c0bee6

Please sign in to comment.