-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from batonac/feat_dynamic_webform
fmt: black & prettier
- Loading branch information
Showing
5 changed files
with
85 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
exclude: 'node_modules|.git' | ||
default_stages: [commit] | ||
default_stages: [pre-commit] | ||
fail_fast: false | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,90 @@ | ||
frappe.ui.form.on("Web Form", { | ||
set_fields(frm) { | ||
let doc = frm.doc; | ||
set_fields(frm) { | ||
let doc = frm.doc; | ||
|
||
let update_options = (options) => { | ||
[frm.fields_dict.web_form_fields.grid, frm.fields_dict.list_columns.grid].forEach( | ||
(obj) => { | ||
obj.update_docfield_property("fieldname", "options", options); | ||
} | ||
); | ||
}; | ||
let update_options = (options) => { | ||
[ | ||
frm.fields_dict.web_form_fields.grid, | ||
frm.fields_dict.list_columns.grid, | ||
].forEach((obj) => { | ||
obj.update_docfield_property("fieldname", "options", options); | ||
}); | ||
}; | ||
|
||
if (!doc.doc_type) { | ||
update_options([]); | ||
frm.set_df_property("amount_field", "options", []); | ||
frm.set_df_property("payer_name_field", "options", []); | ||
frm.set_df_property("payer_email_field", "options", []); | ||
return; | ||
} | ||
if (!doc.doc_type) { | ||
update_options([]); | ||
frm.set_df_property("amount_field", "options", []); | ||
frm.set_df_property("payer_name_field", "options", []); | ||
frm.set_df_property("payer_email_field", "options", []); | ||
return; | ||
} | ||
|
||
update_options([`Fetching fields from ${doc.doc_type}...`]); | ||
update_options([`Fetching fields from ${doc.doc_type}...`]); | ||
|
||
get_fields_for_doctype(doc.doc_type).then((fields) => { | ||
let as_select_option = (df) => ({ | ||
label: df.label, | ||
value: df.fieldname, | ||
}); | ||
update_options(fields.map(as_select_option)); | ||
new Promise((resolve) => | ||
frappe.model.with_doctype(doc.doc_type, resolve) | ||
).then(() => { | ||
const fields = frappe.meta.get_docfields(doc.doc_type).filter((df) => { | ||
return ( | ||
(frappe.model.is_value_type(df.fieldtype) && | ||
!["lft", "rgt"].includes(df.fieldname)) || | ||
["Table", "Table Multiselect"].includes(df.fieldtype) || | ||
frappe.model.layout_fields.includes(df.fieldtype) | ||
); | ||
}); | ||
|
||
// Amount Field Options | ||
let currency_fields = fields | ||
.filter((df) => ["Currency", "Float"].includes(df.fieldtype)) | ||
.map(as_select_option); | ||
if (!currency_fields.length) { | ||
currency_fields = [ | ||
{ | ||
label: `No currency fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("amount_field", "options", currency_fields); | ||
let as_select_option = (df) => ({ | ||
label: df.label, | ||
value: df.fieldname, | ||
}); | ||
|
||
// Payer Name Field Options | ||
let payer_name_fields = fields | ||
.filter((df) => ["Data", "Link"].includes(df.fieldtype)) | ||
.map(as_select_option); | ||
if (!payer_name_fields.length) { | ||
payer_name_fields = [ | ||
{ | ||
label: `No data or link fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("payer_name_field", "options", payer_name_fields); | ||
// Update main field options | ||
update_options(fields.map(as_select_option)); | ||
|
||
// Payer Email Field Options | ||
let payer_email_fields = fields | ||
.filter((df) => ["Email"].includes(df.options)) | ||
.map(as_select_option); | ||
if (!payer_email_fields.length) { | ||
payer_email_fields = [ | ||
{ | ||
label: `No email fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("payer_email_field", "options", payer_email_fields); | ||
}); | ||
} | ||
// Amount Field Options | ||
let currency_fields = fields | ||
.filter((df) => ["Currency", "Float"].includes(df.fieldtype)) | ||
.map(as_select_option); | ||
if (!currency_fields.length) { | ||
currency_fields = [ | ||
{ | ||
label: `No currency fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("amount_field", "options", currency_fields); | ||
|
||
// Payer Name Field Options | ||
let payer_name_fields = fields | ||
.filter((df) => ["Data", "Link"].includes(df.fieldtype)) | ||
.map(as_select_option); | ||
if (!payer_name_fields.length) { | ||
payer_name_fields = [ | ||
{ | ||
label: `No data or link fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("payer_name_field", "options", payer_name_fields); | ||
|
||
// Payer Email Field Options | ||
let payer_email_fields = fields | ||
.filter((df) => ["Email"].includes(df.options)) | ||
.map(as_select_option); | ||
if (!payer_email_fields.length) { | ||
payer_email_fields = [ | ||
{ | ||
label: `No email fields in ${doc.doc_type}`, | ||
value: "", | ||
disabled: true, | ||
}, | ||
]; | ||
} | ||
frm.set_df_property("payer_email_field", "options", payer_email_fields); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters