forked from jdorn/json-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* stepper editor * stepper enable disable logic * added stepper test * fixed code format * use right dist script in tests * fix display error message stepper * added button "type" attribute Co-authored-by: German Bisurgi <[email protected]> Co-authored-by: Marc Mautz <[email protected]>
- Loading branch information
1 parent
9109d1f
commit 84fe806
Showing
8 changed files
with
237 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IntegerEditor } from './integer.js' | ||
|
||
export class StepperEditor extends IntegerEditor { | ||
build () { | ||
super.build() | ||
this.input.setAttribute('type', 'number') | ||
const stepperButtons = this.theme.getStepperButtons(this.input) | ||
this.control.appendChild(stepperButtons) | ||
this.stepperDown = this.control.querySelector('.stepper-down') | ||
this.stepperUp = this.control.querySelector('.stepper-up') | ||
} | ||
|
||
enable () { | ||
super.enable() | ||
this.stepperDown.removeAttribute('disabled') | ||
this.stepperUp.removeAttribute('disabled') | ||
} | ||
|
||
disable () { | ||
super.disable() | ||
this.stepperDown.setAttribute('disabled', true) | ||
this.stepperUp.setAttribute('disabled', true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* global Feature Scenario Event */ | ||
|
||
var assert = require('assert') | ||
|
||
Feature('stepper') | ||
|
||
Scenario('should validate value @stepper', async (I) => { | ||
I.amOnPage('stepper.html') | ||
I.click('.get-value') | ||
I.see('Property must be set.', '[data-schemapath="root.stepper"] div') | ||
assert.equal(await I.grabValueFrom('.value'), '{}') | ||
}) | ||
|
||
Scenario('should be constrained to maximun and minimun values when stepped @stepper', async (I) => { | ||
I.amOnPage('stepper.html') | ||
I.click('.stepper-up') | ||
I.click('.stepper-up') | ||
I.click('.stepper-up') | ||
I.click('.get-value') | ||
I.click('.get-value') | ||
assert.equal(await I.grabValueFrom('.value'), '{"stepper":6}') | ||
I.click('.stepper-down') | ||
I.click('.stepper-down') | ||
I.click('.stepper-down') | ||
I.click('.get-value') | ||
assert.equal(await I.grabValueFrom('.value'), '{"stepper":5}') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,20 @@ | |
<head> | ||
<meta charset="utf-8"/> | ||
<title>Number</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="https://cdn.jsdelivr.net/npm/[email protected]/dist/math.min.js" class="external_mathjs"></script> | ||
<script src="../../dist/jsoneditor.js"></script> | ||
</head> | ||
<body> | ||
|
||
<textarea class="value" cols="30" rows="10"></textarea> | ||
<button class='get-value'>Get Value</button> | ||
<button class='set-value'>Set Value</button> | ||
<div class='container'></div> | ||
<div class='json-editor-container'></div> | ||
|
||
<script> | ||
var container = document.querySelector('.container'); | ||
var jsonEditorContainer = document.querySelector('.json-editor-container'); | ||
var value = document.querySelector('.value'); | ||
|
||
var schema = { | ||
|
@@ -44,12 +47,31 @@ | |
"minimum": 1, | ||
"maximum": 10, | ||
"step": 0.25 | ||
}, | ||
"stepper_number": { | ||
"title": "stepper number", | ||
"format": "stepper", | ||
"type": "number", | ||
"minimum": 1, | ||
"maximum": 10, | ||
"step": 0.25 | ||
}, | ||
"stepper_integer": { | ||
"title": "stepper integer", | ||
"format": "stepper", | ||
"type": "integer", | ||
"minimum": 1, | ||
"maximum": 10, | ||
"step": 0.25 | ||
} | ||
} | ||
}; | ||
|
||
var editor = new JSONEditor(container, { | ||
schema: schema | ||
var editor = new JSONEditor(jsonEditorContainer, { | ||
schema: schema, | ||
theme: 'bootstrap4', | ||
use_default_values: false, | ||
show_errors: 'always' | ||
}); | ||
|
||
document.querySelector('.get-value').addEventListener('click', function () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>Stepper</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="https://cdn.jsdelivr.net/npm/[email protected]/dist/math.min.js" class="external_mathjs"></script> | ||
<script src="../../dist/jsoneditor.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<textarea class="value form-control" rows="10"></textarea> | ||
<button class='get-value'>Get Value</button> | ||
<button class='set-value'>Set Value</button> | ||
<div class='json-editor-container'></div> | ||
</div> | ||
|
||
|
||
<script> | ||
var jsonEditorContainer = document.querySelector('.json-editor-container'); | ||
var value = document.querySelector('.value'); | ||
|
||
var schema = { | ||
"type": "object", | ||
"title": "range", | ||
"properties": { | ||
"stepper": { | ||
'type': 'integer', | ||
'format': 'stepper', | ||
"default": "", | ||
"minimum": 5, | ||
"maximum": 6 | ||
} | ||
} | ||
}; | ||
|
||
var editor = new JSONEditor(jsonEditorContainer, { | ||
schema: schema, | ||
theme: 'bootstrap4', | ||
use_default_values: false, | ||
required_by_default: true, | ||
show_errors: 'always' | ||
}); | ||
|
||
document.querySelector('.get-value').addEventListener('click', function () { | ||
value.value = JSON.stringify(editor.getValue()); | ||
console.log(editor.getValue()); | ||
}); | ||
|
||
document.querySelector('.set-value').addEventListener('click', function () { | ||
editor.setValue({number_range: 2}) | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |