Skip to content

Commit

Permalink
Added dependency chain check
Browse files Browse the repository at this point in the history
  • Loading branch information
gbisurgi committed Apr 16, 2024
1 parent ab0d283 commit 33b8a1b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class AbstractEditor {
const editor = this.jsoneditor.getEditor(path)
const value = editor ? editor.getValue() : undefined

if (!editor || !editor.dependenciesFulfilled) {
if (!editor || !editor.dependenciesFulfilled || !value) {
this.dependenciesFulfilled = false
} else if (Array.isArray(choices)) {
this.dependenciesFulfilled = choices.some(choice => {
Expand Down
12 changes: 12 additions & 0 deletions tests/codeceptjs/issues/issue-gh-1536_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* global Feature Scenario */

Feature('issues')

Scenario('GitHub issue 1536 should remain fixed @issue-1536', async ({ I }) => {
I.amOnPage('issues/issue-gh-1536.html')
I.waitForElement('.je-ready')
I.checkOption('[name="root[dependency_chain_head]')
I.waitForText('dependent_field_one')
I.checkOption('[name="root[dependent_field_one]')
I.waitForText('dependent_field_two')
})
57 changes: 57 additions & 0 deletions tests/pages/issues/issue-gh-1536.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>GitHub Issue 1536</title>
<link rel="stylesheet" id="theme-link" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<script src="../../../dist/nonmin/jsoneditor.js"></script>
</head>
<body>
<div class="container">
<h1>Test</h1>
<a href="https://github.com/json-editor/json-editor/issues/1536">Link to issue</a>
<div id='editor_holder'></div>
</div>

<script>
const value = document.querySelector('#value')
const defaultSchema = {
'title': 'Dependency chain support',
'type': 'object',
'properties': {
'dependent_field_two': {
'type': 'number',
'options': {
'dependencies': {
'dependent_field_one': true
}
}
},
'dependent_field_one': {
'type': 'boolean',
'format': 'checkbox',
'options': {
'dependencies': {
'dependency_chain_head': true
}
}
},
'dependency_chain_head': {
'type': 'boolean',
'default': false,
'format': 'checkbox'
}
}
}

const editor = new JSONEditor(document.getElementById('editor_holder'), {
iconlib: 'fontawesome5',
schema: defaultSchema,
theme: 'bootstrap3'
})
</script>
</body>
</html>

0 comments on commit 33b8a1b

Please sign in to comment.