use validation on settings
This commit is contained in:
parent
2d0968a70b
commit
8c9051076f
1 changed files with 14 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import * as settingActions from '../actions/setting';
|
import * as settingActions from '../actions/setting';
|
||||||
|
import { validate } from '../shared/validators/setting';
|
||||||
|
|
||||||
export default class SettingComponent {
|
export default class SettingComponent {
|
||||||
constructor(wrapper, store) {
|
constructor(wrapper, store) {
|
||||||
|
@ -9,6 +10,9 @@ export default class SettingComponent {
|
||||||
let form = doc.getElementById('vimvixen-settings-form');
|
let form = doc.getElementById('vimvixen-settings-form');
|
||||||
form.addEventListener('submit', this.onSubmit.bind(this));
|
form.addEventListener('submit', this.onSubmit.bind(this));
|
||||||
|
|
||||||
|
let plainJson = form.elements['plain-json'];
|
||||||
|
plainJson.addEventListener('input', this.onPlainJsonChanged.bind(this));
|
||||||
|
|
||||||
store.dispatch(settingActions.load());
|
store.dispatch(settingActions.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +24,16 @@ export default class SettingComponent {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onPlainJsonChanged(e) {
|
||||||
|
try {
|
||||||
|
let settings = JSON.parse(e.target.value);
|
||||||
|
validate(settings);
|
||||||
|
e.target.setCustomValidity('');
|
||||||
|
} catch (err) {
|
||||||
|
e.target.setCustomValidity(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
let { settings } = this.store.getState();
|
let { settings } = this.store.getState();
|
||||||
|
|
||||||
|
|
Reference in a new issue