2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: Add validations for email and phone fields

This commit is contained in:
Faris Ansari 2019-12-27 15:53:13 +05:30
parent 444cd9e441
commit 2e70a0167a
6 changed files with 43 additions and 11 deletions

View File

@ -73,7 +73,10 @@ module.exports = {
fieldname: 'email',
label: 'Email',
fieldtype: 'Data',
required: 1
required: 1,
validate: {
type: 'email'
}
},
{

View File

@ -65,13 +65,19 @@ module.exports = {
fieldname: 'email',
label: 'Email',
fieldtype: 'Data',
placeholder: 'john@doe.com'
placeholder: 'john@doe.com',
validate: {
type: 'email'
}
},
{
fieldname: 'phone',
label: 'Phone',
fieldtype: 'Data',
placeholder: 'Phone'
placeholder: 'Phone',
validate: {
type: 'phone'
}
},
{
fieldname: 'address',

View File

@ -18,7 +18,10 @@ module.exports = {
fieldname: 'email',
label: 'Email',
fieldtype: 'Data',
placeholder: 'john@doe.com'
placeholder: 'john@doe.com',
validate: {
type: 'email'
}
},
{
fieldname: 'displayLogo',
@ -29,7 +32,10 @@ module.exports = {
fieldname: 'phone',
label: 'Phone',
fieldtype: 'Data',
placeholder: '9888900000'
placeholder: '9888900000',
validate: {
type: 'phone'
}
},
{
fieldname: 'address',

View File

@ -39,7 +39,9 @@ module.exports = {
fieldtype: 'Data',
placeholder: 'john@doe.com',
required: 1,
inputType: 'email'
validate: {
type: 'email'
}
},
{

View File

@ -132,7 +132,7 @@ let TwoColumnForm = {
return this.doc.rename(value);
}
this.doc.set(df.fieldname, value);
this.doc.set(df.fieldname, value).catch(this.handleError);
if (this.autosave && this.doc._dirty && !this.doc.isNew()) {
if (df.fieldtype === 'Table') {

View File

@ -18,7 +18,24 @@ export function createNewDatabase() {
if (!filePath.endsWith('.db')) {
filePath = filePath + '.db';
}
resolve(filePath);
if (fs.existsSync(filePath)) {
showMessageDialog({
// prettier-ignore
message: _('A file exists with the same name and it will be overwritten. Are you sure you want to continue?'),
buttons: [
{
label: _('Overwrite'),
action() {
fs.unlinkSync(filePath);
resolve(filePath);
}
},
{ label: _('Cancel'), action() {} }
]
});
} else {
resolve(filePath);
}
}
}
);
@ -138,7 +155,7 @@ export function openQuickEdit({ doctype, name, hideFields, defaults = {} }) {
}
export function handleErrorWithDialog(e, doc) {
let errorMessage;
let errorMessage = e.message || _('An error occurred');
if (e.type === frappe.errors.LinkValidationError) {
errorMessage = _('{0} {1} is linked with existing records.', [
doc.doctype,
@ -146,8 +163,6 @@ export function handleErrorWithDialog(e, doc) {
]);
} else if (e.type === frappe.errors.DuplicateEntryError) {
errorMessage = _('{0} {1} already exists.', [doc.doctype, doc.name]);
} else {
errorMessage = _('An error occurred.');
}
showMessageDialog({