I have an Admin Grid with one column named min_weight. This column has the datatype decimal (5,2) in the database. The default value for the column is NULL. If I try to save an entry with the Admin form, Magento always fills the empty column with 0.00. But I would like to have the value NULL in the database not 0.00. Is there a way to stop Magento 2 from formatting the column value as 0.00?
This is the field configuration in the form.xml:
<field name="min_weight" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">zones</item>
</item>
</argument>
<settings>
<dataType>text</dataType>
<label translate="true">Min. Weight</label>
<dataScope>min_weight</dataScope>
<validation>
<rule name="required-entry" xsi:type="boolean">false</rule>
</validation>
</settings>
</field>
The form data that is submitted when pressing the save button contains an empty value for this attribute (which is correct):
items[985][name]: test
items[985][min_weight]
But Magento 2 writes this empty value with 0.00 in the database.
The problem exists regardless of whether I modify the record via inline editing or on the Edit page, or create a new record.
I would be very thankful for any advice!
nullable="true"
, and with defaul valuenull
NULL
. If I add a new entry to my table via phpMyAdmin the min_weight column is correctly saves asNULL
. So I guess that the issue is related to the way magento 2 saves the entry.