Implemented #183: display a checkbox left from boolean values, so you can easily switch between true/false.

This commit is contained in:
jos 2016-01-12 15:18:11 +01:00
parent 5a6ca406da
commit 0690202f3a
6 changed files with 38 additions and 7 deletions

View File

@ -7,6 +7,8 @@ https://github.com/josdejong/jsoneditor
- Implemented support for JSON schema validation, powered by `ajv`. A JSON - Implemented support for JSON schema validation, powered by `ajv`. A JSON
schema can be configured via the option `schema` or the method `setSchema`. schema can be configured via the option `schema` or the method `setSchema`.
- Implemented #183: display a checkbox left from boolean values, so you can
easily switch between true/false.
- Added a minimalist bundle to the `dist` folder, excluding `ace` and `ajv`. - Added a minimalist bundle to the `dist` folder, excluding `ace` and `ajv`.
- Fixed an error throw when switching to mode "code" via the menu. - Fixed an error throw when switching to mode "code" via the menu.
- Fixed interfering shortcut keys: changed quick keys to select multiple fields - Fixed interfering shortcut keys: changed quick keys to select multiple fields

View File

@ -34,9 +34,11 @@ Supported browsers: Chrome, Firefox, Safari, Opera, Internet Explorer 9+.
- Format and compact JSON. - Format and compact JSON.
- Colorized code (powered by [Ace](https://ace.c9.io)). - Colorized code (powered by [Ace](https://ace.c9.io)).
- Inspect JSON (powered by [Ace](https://ace.c9.io)). - Inspect JSON (powered by [Ace](https://ace.c9.io)).
- JSON schema validation (powered by [ajv](https://github.com/epoberezkin/ajv)).
### Text editor ### Text editor
- Format and compact JSON. - Format and compact JSON.
- JSON schema validation (powered by [ajv](https://github.com/epoberezkin/ajv)).
## Documentation ## Documentation

View File

@ -980,7 +980,7 @@ Node.prototype.removeChild = function(node) {
/** /**
* Remove a child node node from this node * Remove a child node node from this node
* This method is equal to Node.removeChild, except that _remove firex an * This method is equal to Node.removeChild, except that _remove fire an
* onChange event. * onChange event.
* @param {Node} node * @param {Node} node
* @private * @private
@ -1184,6 +1184,29 @@ Node.prototype._updateDomValue = function () {
domValue.title = ''; domValue.title = '';
} }
// show checkbox when the value is a boolean
if (type === 'boolean') {
if (!this.dom.checkbox) {
this.dom.checkbox = document.createElement('input');
this.dom.checkbox.type = 'checkbox';
this.dom.tdCheckbox = document.createElement('td');
this.dom.tdCheckbox.className = 'jsoneditor-tree';
this.dom.tdCheckbox.appendChild(this.dom.checkbox);
this.dom.tdValue.parentNode.insertBefore(this.dom.tdCheckbox, this.dom.tdValue);
}
this.dom.checkbox.checked = this.value;
}
else {
// cleanup checkbox when displayed
if (this.dom.tdCheckbox) {
this.dom.tdCheckbox.parentNode.removeChild(this.dom.tdCheckbox);
delete this.dom.tdCheckbox;
delete this.dom.checkbox;
}
}
// strip formatting from the contents of the editable div // strip formatting from the contents of the editable div
util.stripFormatting(domValue); util.stripFormatting(domValue);
} }
@ -1984,6 +2007,12 @@ Node.prototype.onEvent = function (event) {
} }
} }
// swap the value of a boolean when the checkbox displayed left is clicked
if (type == 'change' && target == dom.checkbox) {
this.dom.value.innerHTML = !this.value;
this._getDomValue();
}
// value events // value events
var domValue = dom.value; var domValue = dom.value;
if (target == domValue) { if (target == domValue) {

View File

@ -397,7 +397,7 @@ textmode.validate = function () {
// no valid JSON, don't validate // no valid JSON, don't validate
} }
// only validate the JSON when parsing the JSON succeeeded // only validate the JSON when parsing the JSON succeeded
if (doValidate && this.validateSchema) { if (doValidate && this.validateSchema) {
//console.time('validate'); // TODO: clean up time measurement //console.time('validate'); // TODO: clean up time measurement
var valid = this.validateSchema(json); var valid = this.validateSchema(json);

View File

@ -370,12 +370,10 @@ treemode.validate = function () {
return; return;
} }
//console.time('validate'); // TODO: clean up time measurement // validate the JSON
var valid = this.validateSchema(root.getValue()); var valid = this.validateSchema(root.getValue());
//console.timeEnd('validate');
// apply all new errors
if (!valid) { if (!valid) {
// apply all new errors
this.errorNodes = this.validateSchema.errors this.errorNodes = this.validateSchema.errors
.map(function findNode (error) { .map(function findNode (error) {
return { return {

View File

@ -64,7 +64,7 @@
}; };
var options = { var options = {
mode: 'text', mode: 'tree',
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
onError: function (err) { onError: function (err) {
console.error(err); console.error(err);