Cannot set Default value for a field in Modal dialog using Client Script

Hello,

I am building a modal dialog in Client Script. I am using the following code to add a filed to the dialog but I cannot set its default value.

                    {
                        label: __('Input Wire Size'),
                        fieldname: 'wire_size',
                        fieldtype: 'Float',
                        precision: 2,
                        reqd: 1,
                        default: wire_size_is
                    },

When the dialog opens the field comes up blank, that is with 0.0.

TIA

Yogi Yang

If you set the default value as a numerical value it should work, or if you need to change it try declaring the wire_size_is variable before your frappe.ui.dialog code

var wire_size_is= 5 ///or source of your default value
let d = new frappe.ui.Dialog({
    title: 'Input Wire Size,
    fields: [
        {
                    {
                        label: __('Input Wire Size'),
                        fieldname: 'wire_size',
                        fieldtype: 'Float',
                        precision: 2,
                        reqd: 1,
                        default: wire_size_is
                    },
    ],

1 Like