Change default behavior on edit: for empty fields, from empty string to null

Change default behavior on edit: for empty fields, from empty string to null

nidedinidedi Posts: 13Questions: 1Answers: 0
edited June 2013 in Editor
I have certain int attributes in a database table, which are allowed to have a value of null. When I try to edit a row on a data table and leave these fields empty, I get an error (probably because the program is setting them to an empty string, which isn't a valid value because my attribute is an int). How do I change this behavior? When editing a row in a data table, how do I tell the program to give the empty fields a value of null instead of an empty string?

Thank you.

Replies

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin
    You would need to use a `setFormatter` function for the field. The value being read from the input field is an empty string, so I think what it is doing at the moment is actually correct - although not quite want you want. Using a setFormatter you could check if the field is an empty string, and if so have the formatter return null, which will then be used for the database.

    Regards,
    Allan
  • nidedinidedi Posts: 13Questions: 1Answers: 0
    Thank you Allan. I managed to solve the problem using this method.
This discussion has been closed.