use validation on settings

jh-changes
Shin'ya Ueoka 7 years ago
parent 2d0968a70b
commit 8c9051076f
  1. 14
      src/components/setting.js

@ -1,4 +1,5 @@
import * as settingActions from '../actions/setting';
import { validate } from '../shared/validators/setting';
export default class SettingComponent {
constructor(wrapper, store) {
@ -9,6 +10,9 @@ export default class SettingComponent {
let form = doc.getElementById('vimvixen-settings-form');
form.addEventListener('submit', this.onSubmit.bind(this));
let plainJson = form.elements['plain-json'];
plainJson.addEventListener('input', this.onPlainJsonChanged.bind(this));
store.dispatch(settingActions.load());
}
@ -20,6 +24,16 @@ export default class SettingComponent {
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() {
let { settings } = this.store.getState();