diff options
| author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 12:15:35 +0900 | 
|---|---|---|
| committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 12:17:58 +0900 | 
| commit | 8c9051076f7782b898ab2f848b9afe4a694c3065 (patch) | |
| tree | 0fcacdad33a51cf7611af77e601443eb827c2498 /src | |
| parent | 2d0968a70b78710e854075d96a8e643e2cd2b3a7 (diff) | |
use validation on settings
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/setting.js | 14 | 
1 files changed, 14 insertions, 0 deletions
diff --git a/src/components/setting.js b/src/components/setting.js index afbd56c..1f3b3fe 100644 --- a/src/components/setting.js +++ b/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();  | 
