I am creating a new composite field type that represents financial debt information. Each field consists of several sub-fields for values such as Amount owed, Interest rate, Repayment amount etc. This field is added to a content type as a multiple-instance field and users can add an unlimited number of these items.
I have built the settings forms, widgets, validators and formatters and it all works great when I fill out all the fields and submit the node. The data is written into the custom field table OK and the values persist when the node is edited again. The multi-instance field creation works as it should.
The problem is that some of the sub-fields are optional, but if they are left empty then I get a PDO error when the node is submitted:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: '' for column 'field_cc_repayment_amount'
repayment_amount is an optional numeric sub-field. It is declared in the .install file like this:
'repayment_amount' => array(
'type' => 'numeric',
'precision' => 11,
'scale' => 2,
'not null' => FALSE,
),