fix: make percent precision dynamic (#37523)
This commit is contained in:
parent
26dddcb9d8
commit
fcc672315f
4 changed files with 19 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ import "./base_input";
|
|||
import "./data";
|
||||
import "./int";
|
||||
import "./float";
|
||||
import "./percent";
|
||||
import "./currency";
|
||||
import "./date";
|
||||
import "./time";
|
||||
|
|
|
|||
|
|
@ -32,5 +32,3 @@ frappe.ui.form.ControlFloat = class ControlFloat extends frappe.ui.form.ControlI
|
|||
return this.df.precision || cint(frappe.boot.sysdefaults.float_precision, null);
|
||||
}
|
||||
};
|
||||
|
||||
frappe.ui.form.ControlPercent = frappe.ui.form.ControlFloat;
|
||||
|
|
|
|||
13
frappe/public/js/frappe/form/controls/percent.js
Normal file
13
frappe/public/js/frappe/form/controls/percent.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
frappe.ui.form.ControlPercent = class ControlPercent extends frappe.ui.form.ControlFloat {
|
||||
format_for_input(value) {
|
||||
if (value === null || value === undefined || isNaN(Number(value))) {
|
||||
return "";
|
||||
}
|
||||
const precision = value.toString().split(".")[1]?.length || 0;
|
||||
return format_number(
|
||||
value,
|
||||
this.get_number_format(),
|
||||
Math.min(this.get_precision(), precision)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
@ -94,12 +94,15 @@ frappe.form.formatters = {
|
|||
if (value === null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const valuePrecision = value.toString().split(".")[1]?.length || 0;
|
||||
const precision =
|
||||
docfield.precision ||
|
||||
cint(frappe.boot.sysdefaults && frappe.boot.sysdefaults.float_precision) ||
|
||||
2;
|
||||
return frappe.form.formatters._right(format_number(value, null, precision) + "%", options);
|
||||
return frappe.form.formatters._right(
|
||||
format_number(value, null, Math.min(precision, valuePrecision)) + "%",
|
||||
options
|
||||
);
|
||||
},
|
||||
Rating: function (value, docfield) {
|
||||
let rating_html = "";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue