Optional field's default value must be NULL

Hey!

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.

1 Like

I see that it’s made “be design” in dockfield.json

{
 "default": "0",
 "depends_on": "eval:!in_list([\"Check\", \"Currency\", \"Float\", \"Int\", \"Percent\", \"Rating\", \"Select\", \"Table\", \"Table MultiSelect\"], doc.fieldtype)",
 "fieldname": "not_nullable",
 "fieldtype": "Check",
 "label": "Not Nullable"
},

Also here: apps/frappe/frappe/database/schema.py

NOT_NULL_TYPES = ("Check", "Int", "Currency", "Float", "Percent")

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

Does someone know why?

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.

Look here:

I practically have to wrap every numerical field with a checkbox.
0 (zero) is a valid (and meaningful) value here.

Should I make them all required?
Then I can’t draft the data and work on it gradually. It will be “all-or-nothing” form.

Any other approaches you guys may suggest for such a situation?