mirror of
https://github.com/frappe/books.git
synced 2025-01-25 16:18:33 +00:00
fix: Inline errors in TwoColumnForm
This commit is contained in:
parent
f4fc9703bb
commit
463631d306
@ -46,8 +46,10 @@
|
|||||||
:class="{ 'border-b': !noBorder }"
|
:class="{ 'border-b': !noBorder }"
|
||||||
:style="style"
|
:style="style"
|
||||||
>
|
>
|
||||||
<div class="py-2 pl-4 flex items-center text-gray-600">
|
<div class="py-2 pl-4 flex text-gray-600">
|
||||||
{{ df.label }}
|
<div class="py-1">
|
||||||
|
{{ df.label }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2 pr-4" @click="activateInlineEditing(df)">
|
<div class="py-2 pr-4" @click="activateInlineEditing(df)">
|
||||||
<FormControl
|
<FormControl
|
||||||
@ -66,6 +68,12 @@
|
|||||||
@focus="activateInlineEditing(df)"
|
@focus="activateInlineEditing(df)"
|
||||||
@new-doc="newdoc => onChange(df, newdoc.name)"
|
@new-doc="newdoc => onChange(df, newdoc.name)"
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
class="text-sm text-red-600 mt-2 pl-2"
|
||||||
|
v-if="errors[df.fieldname]"
|
||||||
|
>
|
||||||
|
{{ errors[df.fieldname] }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -76,7 +84,7 @@
|
|||||||
import frappe from 'frappejs';
|
import frappe from 'frappejs';
|
||||||
import FormControl from '@/components/Controls/FormControl';
|
import FormControl from '@/components/Controls/FormControl';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import { handleErrorWithDialog } from '@/utils';
|
import { getErrorMessage, handleErrorWithDialog } from '@/utils';
|
||||||
|
|
||||||
let TwoColumnForm = {
|
let TwoColumnForm = {
|
||||||
name: 'TwoColumnForm',
|
name: 'TwoColumnForm',
|
||||||
@ -96,7 +104,8 @@ let TwoColumnForm = {
|
|||||||
inlineEditField: null,
|
inlineEditField: null,
|
||||||
inlineEditDoc: null,
|
inlineEditDoc: null,
|
||||||
inlineEditFields: null,
|
inlineEditFields: null,
|
||||||
inlineEditDisplayField: null
|
inlineEditDisplayField: null,
|
||||||
|
errors: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
@ -132,7 +141,13 @@ let TwoColumnForm = {
|
|||||||
return this.doc.rename(value);
|
return this.doc.rename(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.doc.set(df.fieldname, value).catch(this.handleError);
|
// reset error messages
|
||||||
|
this.$set(this.errors, df.fieldname, null);
|
||||||
|
|
||||||
|
this.doc.set(df.fieldname, value).catch(e => {
|
||||||
|
// set error message for this field
|
||||||
|
this.$set(this.errors, df.fieldname, getErrorMessage(e, this.doc));
|
||||||
|
});
|
||||||
|
|
||||||
if (this.autosave && this.doc._dirty && !this.doc.isNew()) {
|
if (this.autosave && this.doc._dirty && !this.doc.isNew()) {
|
||||||
if (df.fieldtype === 'Table') {
|
if (df.fieldtype === 'Table') {
|
||||||
|
11
src/utils.js
11
src/utils.js
@ -184,7 +184,7 @@ export function openQuickEdit({ doctype, name, hideFields, defaults = {} }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleErrorWithDialog(e, doc) {
|
export function getErrorMessage(e, doc) {
|
||||||
let errorMessage = e.message || _('An error occurred');
|
let errorMessage = e.message || _('An error occurred');
|
||||||
if (e.type === frappe.errors.LinkValidationError) {
|
if (e.type === frappe.errors.LinkValidationError) {
|
||||||
errorMessage = _('{0} {1} is linked with existing records.', [
|
errorMessage = _('{0} {1} is linked with existing records.', [
|
||||||
@ -194,11 +194,12 @@ export function handleErrorWithDialog(e, doc) {
|
|||||||
} else if (e.type === frappe.errors.DuplicateEntryError) {
|
} else if (e.type === frappe.errors.DuplicateEntryError) {
|
||||||
errorMessage = _('{0} {1} already exists.', [doc.doctype, doc.name]);
|
errorMessage = _('{0} {1} already exists.', [doc.doctype, doc.name]);
|
||||||
}
|
}
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
showMessageDialog({
|
export function handleErrorWithDialog(e, doc) {
|
||||||
message: errorMessage
|
let errorMessage = getErrorMessage(e, doc);
|
||||||
});
|
showMessageDialog({ message: errorMessage });
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user