Show form errors for group dialog
This commit is contained in:
@@ -17,7 +17,7 @@ const dialog = useTemplateRef('dialog');
|
||||
// also determines if new or edit mode
|
||||
const group = ref(null);
|
||||
const busy = ref(false);
|
||||
const formError = ref('');
|
||||
const formError = ref({});
|
||||
const name = ref('');
|
||||
const users = ref([]);
|
||||
const allUsers = ref([]);
|
||||
@@ -26,19 +26,21 @@ const allApps = ref([]);
|
||||
|
||||
async function onSubmit() {
|
||||
busy.value = true;
|
||||
formError.value = '';
|
||||
formError.value = {};
|
||||
|
||||
if (group.value) {
|
||||
const [error] = await groupsModel.update(group.value.id, name.value, users.value, apps.value);
|
||||
if (error) {
|
||||
formError.value = error.body ? error.body.message : 'Internal error';
|
||||
if (error.body && error.body.message.indexOf('name') === 0) formError.value.name = error.body.message;
|
||||
else formError.value.generic = error.body ? error.body.message : 'Internal error';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
} else {
|
||||
const [error] = await groupsModel.add(name.value, users.value, apps.value);
|
||||
if (error) {
|
||||
formError.value = error.body ? error.body.message : 'Internal error';
|
||||
if (error.body && error.body.message.indexOf('name') === 0) formError.value.name = error.body.message;
|
||||
else formError.value.generic = error.body ? error.body.message : 'Internal error';
|
||||
busy.value = false;
|
||||
return console.error(error);
|
||||
}
|
||||
@@ -53,6 +55,8 @@ defineExpose({
|
||||
async open(g = null) {
|
||||
group.value = g;
|
||||
name.value = g ? g.name : '';
|
||||
formError.value = {};
|
||||
busy.value = false;
|
||||
|
||||
let [error, result] = await usersModel.list();
|
||||
if (error) return console.error(error);
|
||||
@@ -87,9 +91,12 @@ defineExpose({
|
||||
<fieldset :disabled="busy">
|
||||
<input type="submit" style="display: none;" />
|
||||
|
||||
<div class="error-label" v-if="formError.generic">{{ formError.generic }}</div>
|
||||
|
||||
<FormGroup>
|
||||
<label for="nameInput">{{ $t('users.group.name') }}</label>
|
||||
<TextInput id="nameInput" v-model="name" />
|
||||
<div class="error-label" v-if="formError.name">{{ formError.name }}</div>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup>
|
||||
|
||||
Reference in New Issue
Block a user