2
0
mirror of https://github.com/frappe/books.git synced 2024-09-19 19:19:02 +00:00

fix: isRequired handling

- add support for default value in fields
This commit is contained in:
18alantom 2023-09-18 15:21:56 +05:30 committed by Alan
parent 387688cebb
commit 316f052c53
4 changed files with 17 additions and 0 deletions

View File

@ -92,4 +92,5 @@ export type RawCustomField = {
options?: string; options?: string;
target?: string; target?: string;
references?: string; references?: string;
default?: string;
}; };

View File

@ -150,5 +150,6 @@ export class CustomField extends Doc {
this.fieldtype === 'Select' || this.fieldtype === 'AutoComplete', this.fieldtype === 'Select' || this.fieldtype === 'AutoComplete',
target: () => this.fieldtype === 'Link' || this.fieldtype === 'Table', target: () => this.fieldtype === 'Link' || this.fieldtype === 'Table',
references: () => this.fieldtype === 'DynamicLink', references: () => this.fieldtype === 'DynamicLink',
default: () => !!this.isRequired,
}; };
} }

View File

@ -94,6 +94,11 @@
"fieldtype": "Check", "fieldtype": "Check",
"default": false "default": false
}, },
{
"fieldname": "default",
"label": "Default",
"fieldtype": "Data"
},
{ {
"fieldname": "section", "fieldname": "section",
"label": "Form Section", "label": "Form Section",
@ -128,6 +133,7 @@
"fieldname", "fieldname",
"fieldtype", "fieldtype",
"isRequired", "isRequired",
"default",
"options", "options",
"target", "target",
"references", "references",

View File

@ -296,6 +296,7 @@ function getFieldMapFromRawCustomFields(
section, section,
tab, tab,
options: rawOptions, options: rawOptions,
default: defaultValue,
target, target,
references, references,
} }
@ -343,6 +344,14 @@ function getFieldMapFromRawCustomFields(
(field as DynamicLinkField).references = references; (field as DynamicLinkField).references = references;
} }
if (field.required && defaultValue != null) {
field.default = defaultValue;
}
if (field.required && field.default == null) {
field.required = false;
}
map[parent].push(field); map[parent].push(field);
return map; return map;
}, },