I ran in this problem where my numeric fields (int | currency | percent | etc.) set 0 by default.
But these fields are optional and 0 is valid value and quite misleading.
Real world example: custom DOCTYPE “Credit Card”, “annual fee” or “APR”. If I miss them and save form - both will be 0, where in reality they are not. So this new card will get into report for “0% APR cards”.
it’s a very simplified example, I could make them mandatory, I could do client script for validation, etc.
This is not the point. The point is value must be NULL or valid. It’s a very useful when I need to create a draft record and come back to it later when data is available.
Is there a way that field is nullable, and form input has NO value when shown until user provide value?
Thanks!
P.S
Data type field for numeric values doesn’t sound right.
if self.fieldtype in NOT_NULL_TYPES:
null = False
if self.fieldtype in ("Check", "Int"):
default = cint(self.default)
elif self.fieldtype in ("Currency", "Float", "Percent"):
default = flt(self.default)
elif (
self.default
and (self.default not in frappe.db.DEFAULT_SHORTCUTS)
and not cstr(self.default).startswith(":")
):
default = frappe.db.escape(self.default)
if self.not_nullable and null:
if default is None:
default = get_not_null_defaults(self.fieldtype)
if isinstance(default, str):
default = frappe.db.escape(default)
null = False
Basically i have the same issue. I have a Currency field which has default value as 0. Even when i customize the fieldtype to remove the default, the system again show 0 when i need it to be blank.