Add validation

This commit is contained in:
Stanislav Romanov 2022-10-15 09:55:37 +03:00
parent 51e34162e3
commit 4a8582eba9
3 changed files with 27 additions and 6 deletions

View file

@ -7,6 +7,7 @@
@language='json'
@sendValue={{this.save}}
@invoker={{this.invoker}}
@onDidChangeValidation={{this.onDidChangeValidation}}
class='h-40'
/>
</Form::Element>

View file

@ -49,4 +49,9 @@ export default class FormIndexSettingComponent extends Component {
this.error = error.error || error;
}
}
@action
onDidChangeValidation(error) {
this.error = error;
}
}

View file

@ -1,6 +1,7 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { Uri, editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
import { registerDestructor } from '@ember/destroyable';
// This is needed because the SimpleWorker.js in monaco-editor has the following code:
// loaderConfiguration = self.requirejs.s.contexts._.config;
@ -57,15 +58,29 @@ export default class MonacoEditorComponent extends Component {
// }
// Autoresize height of element
this.editor.onDidContentSizeChange(() => {
const contentHeight = Math.min(
Math.max(this.editor.getContentHeight(), 160),
420
const onDidContentSizeChangeHandler = this.editor.onDidContentSizeChange(
() => {
const contentHeight = Math.min(
Math.max(this.editor.getContentHeight(), 160),
420
);
el.style.height = `${contentHeight + 1}px`;
this.editor.layout();
}
);
registerDestructor(this, onDidContentSizeChangeHandler.dispose);
const onDidChangeMarkersHandler = editor.onDidChangeMarkers((uris) => {
const error = uris.find(
(item) => item.toString() === this.modelUri.toString()
);
el.style.height = `${contentHeight + 1}px`;
this.editor.layout();
this.args.onDidChangeValidation?.(
error ? 'Error: the value is invalid' : false
);
});
registerDestructor(this, onDidChangeMarkersHandler.dispose);
}
@action