Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/object array readonly #1474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/editors/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ export class ArrayEditor extends AbstractEditor {
this.addControls()
}

postBuild () {
super.postBuild()

if (this.schema.readOnly || this.schema.readonly) {
this.disable()
}
}

onChildEditorChange (editor) {
this.refreshValue()
this.refreshTabs(true)
Expand Down
4 changes: 4 additions & 0 deletions src/editors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ export class ObjectEditor extends AbstractEditor {
/* Do it again now that we know the approximate heights of elements */
this.layoutEditors()
}

if (this.schema.readOnly || this.schema.readonly) {
this.disable()
}
}

deactivateNonRequiredProperties () {
Expand Down
7 changes: 7 additions & 0 deletions tests/codeceptjs/editors/array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const { DEFAULT_WAIT_TIME } = require('../test-config')

Feature('array')

Scenario('should be readonly if specified and not disabled @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.waitForElement('.je-ready', DEFAULT_WAIT_TIME)
I.seeDisabledAttribute('[name="root[array][0]"]')
I.seeDisabledAttribute('[name="root[array][1]"]')
})

Scenario('Should display properties enum titles in items headerTemplate @headerTemplate', async ({ I }) => {
I.amOnPage('array-header-template.html')
I.waitForElement('.je-ready', DEFAULT_WAIT_TIME)
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/button_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Scenario('should not leave any footprints in result', async ({ I }) => {
I.waitForValue('.value', JSON.stringify({ textinput: '' }))
})

Scenario('should be disabled if "readonly" is specified', async ({ I }) => {
Scenario('should be disabled if "readonly" is specified @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.waitForElement('.je-ready', DEFAULT_WAIT_TIME)
I.seeDisabledAttribute('[data-schemapath="root.button"] button')
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/checkbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { DEFAULT_WAIT_TIME } = require('../test-config')

Feature('checkbox')

Scenario('should be disabled if "readonly" is specified', async ({ I }) => {
Scenario('should be disabled if "readonly" is specified @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.waitForText('READY', DEFAULT_WAIT_TIME, '.state')
I.seeDisabledAttribute('[name="root[checkbox]"]')
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/integer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Scenario('should respect step by incrementing and decrementing the value of a ra
I.waitForValue('.value', '{"integer":5,"integer_number":5,"integer_range":5}')
})

Scenario('should be readonly if specified and not disabled', async ({ I }) => {
Scenario('should be readonly if specified and not disabled @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.seeReadOnlyAttribute('[name="root[integer]"]')
})
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/multiselect_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Feature('multiselect')

Scenario('should be disabled if "readonly" is specified', async ({ I }) => {
Scenario('should be disabled if "readonly" is specified @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.seeDisabledAttribute('[name="root[multiselect]"]')
})
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/number_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Scenario('should respect step by incrementing and decrementing the value of a ra
I.waitForValue('.value', '{"number":5.75,"number_number":5.75,"number_range":5.75,"stepper_number_default":5,"stepper_integer_default":5}')
})

Scenario('should be readonly if specified and not disabled @number', async ({ I }) => {
Scenario('should be readonly if specified and not disabled @number @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.seeReadOnlyAttribute('[name="root[number]"]')
})
Expand Down
7 changes: 7 additions & 0 deletions tests/codeceptjs/editors/object_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const { DEFAULT_WAIT_TIME } = require('../test-config')

Feature('object')

Scenario('should be readonly if specified and not disabled @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.waitForElement('.je-ready', DEFAULT_WAIT_TIME)
I.seeDisabledAttribute('[name="root[object][string]"]')
I.seeDisabledAttribute('[name="root[object][number]"]')
})

Scenario('@case-sensitive-property-search', async ({ I }) => {
I.amOnPage('object-case-sensitive-property-search-true.html')
I.click('.json-editor-btn-edit_properties')
Expand Down
3 changes: 1 addition & 2 deletions tests/codeceptjs/editors/radio_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Feature('radio')

Scenario('should be disabled if "readonly" is specified', async ({ I }) => {
Scenario('should be disabled if "readonly" is specified @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')

I.seeDisabledAttribute('[id="root[radio][0]"]')
I.seeDisabledAttribute('[id="root[radio][1]"]')
})
3 changes: 1 addition & 2 deletions tests/codeceptjs/editors/rating_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Feature('rating')

Scenario('should be disabled if "readonly" is specified', async ({ I }) => {
Scenario('should be disabled if "readonly" is specified @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')

I.seeDisabledAttribute('[id="root[rating]5"]')
I.seeDisabledAttribute('[id="root[rating]4"]')
I.seeDisabledAttribute('[id="root[rating]3"]')
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Feature('select')

Scenario('should return correct booleans values when selected', async ({ I }) => {
Scenario('should return correct booleans values when selected @readOnly', async ({ I }) => {
I.amOnPage('select.html')
I.click('.get-value')
I.waitForValue('.value', '{"boolean":true}')
Expand Down
2 changes: 1 addition & 1 deletion tests/codeceptjs/editors/string_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Scenario('Should work correctly in arrays @optional', async ({ I }) => {
I.switchTo()
})

Scenario('should be readonly if specified and not disabled', async ({ I }) => {
Scenario('should be readonly if specified and not disabled @readOnly', async ({ I }) => {
I.amOnPage('read-only.html')
I.seeReadOnlyAttribute('[name="root[string]"]')
})
Expand Down
36 changes: 32 additions & 4 deletions tests/pages/read-only.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>readonly</title>
<meta charset="utf-8"/>
<script src="../../dist/jsoneditor.js"></script>
<title>readonly</title>
<meta charset="utf-8"/>
<script src="../../dist/jsoneditor.js"></script>
</head>
<body>

Expand Down Expand Up @@ -86,6 +86,34 @@ <h1>Test</h1>
"title": "button",
"format": "button",
"readOnly": true
},
"array": {
"type": "array",
"minItems": 2,
"readOnly": true,
"items": {
"readOnly": false,
"title": "string",
"type": "string",
"default": "some value"
}
},
"object": {
"type": "object",
"title": "Object",
"readOnly": true,
"properties": {
"string": {
"title": "string",
"type": "string",
"default": "some value"
},
"number": {
"title": "number",
"type": "number",
"default": 5.5
}
}
}
}
};
Expand All @@ -94,7 +122,7 @@ <h1>Test</h1>
schema: schema
});

editor.on('ready',function() {
editor.on('ready', function () {
state.innerText = 'READY'
});

Expand Down
Loading