setFormatter always returning ifEmpty format
setFormatter always returning ifEmpty format
rwgreenwood
Posts: 43Questions: 13Answers: 0
in Editor
I have this on an editor field
->setFormatter('Format::ifEmpty', null),
but I am always getting null, even if it's not empty.
The field is valued in the form data properly.
I can't see what I am missing.
Thanks
This discussion has been closed.
Answers
Could you show me your full PHP code and Javascript code please?
Thanks,
Allan
Sure. It's the acres_inspected column and it is a numeric in the database.
PHP :
and the javascript:
I must confess, I don't immediately see why that isn't working I'm afraid, and I've not been able to reproduce it here.
Could you add a new line immediately before
->process( $_POST )
which is:That will just include the SQL that Editor is executing in the JSON response, which you will be able to see in the Network inspector of your browser. Could you show me what that says?
Thanks,
Allan
See next comment for info
OK, went to 1.6 and got this:
An SQL error occurred: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: ""An SQL error occurred: SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block{"fieldErrors":[],"error":"Error executing SQL for data get. Enable SQL debug using
->debug(true)
","data":[],"ipOpts":[],"cancelled":[],"debugSql":[{"query":"SELECT * FROM service_haycert WHERE service_haycert.id = :where_0 ","bindings":[{"name":":where_0","value":"3","type":null}]},{"query":"UPDATE service_haycert SET case_id = :case_id, certifcate_date = :certifcate_date, staff_id = :staff_id, field_description = :field_description, acres_inspected = :acres_inspected, cutting = :cutting, forage_product = :forage_product, requirement_level = :requirement_level, weeds_noted = :weeds_noted, additional_comments = :additional_comments WHERE service_haycert.id = :where_0 ","bindings":[{"name":":case_id","value":"3596","type":null},{"name":":certifcate_date","value":"2017-06-15","type":null},{"name":":staff_id","value":"","type":null},{"name":":field_description","value":"","type":null},{"name":":acres_inspected","value":null,"type":null},{"name":":cutting","value":"First","type":null},{"name":":forage_product","value":"Alfalfa Grass","type":null},{"name":":requirement_level","value":"A","type":null},{"name":":weeds_noted","value":"","type":null},{"name":":additional_comments","value":"","type":null},{"name":":where_0","value":"3","type":null}]},{"query":"SELECT service_haycert.id as \"service_haycert.id\", service_haycert.case_id as \"service_haycert.case_id\", service_haycert.certifcate_date as \"service_haycert.certifcate_date\", service_haycert.staff_id as \"service_haycert.staff_id\", staff.last_name as \"staff.last_name\", staff.first_name as \"staff.first_name\", service_haycert.field_description as \"service_haycert.field_description\", service_haycert.acres_inspected as \"service_haycert.acres_inspected\", service_haycert.package_type as \"service_haycert.package_type\", service_haycert.cutting as \"service_haycert.cutting\", service_haycert.forage_product as \"service_haycert.forage_product\", service_haycert.requirement_level as \"service_haycert.requirement_level\", service_haycert.weeds_noted as \"service_haycert.weeds_noted\", service_haycert.additional_comments as \"service_haycert.additional_comments\" FROM service_haycert LEFT JOIN staff ON staff.staff_id = service_haycert.staff_id WHERE service_haycert.case_id = :where_0 AND service_haycert.id = :where_1 ","bindings":[{"name":":where_0","value":"3596","type":null},{"name":":where_1","value":"3","type":null}]}]}This is a postgres database, the column is numeric and allows nulls. Thanks in advance.
Sorry about this - one more bit of information needed. Could you show me the data that is set to the server with the edit request? That is shown in the "Headers" tab of the network request.
Thanks,
Allan
Allan, here you go.
action:edit
data[row_3][service_haycert][staff_id]:
data[row_3][service_haycert][certifcate_date]:06/15/2017
data[row_3][service_haycert][case_id]:3596
data[row_3][service_haycert][cutting]:First
data[row_3][service_haycert][forage_product]:Alfalfa Grass
data[row_3][service_haycert][requirement_level]:A
data[row_3][service_haycert][weeds_noted]:
data[row_3][service_haycert][acres_inspected]:
data[row_3][service_haycert][field_description]:
data[row_3][service_haycert][additional_comments]:
case_id:3596
Thank you. It is showing:
So it is correct that the
null
would be submitted into the database under that condition.However, that obviously isn't what you are expecting to happen - do you have a value in that field in the Editor form?
Allan
Sorry I've been slow getting back to this. This is my editor form setup:
Is that what you were asking?
I think I see the issue was something completely different than what I had first thought. Once I fixed what the REAL error was, it seems to be functioning properly. Thanks for you time, it helped me work through it.
Thanks for posting back - great to hear you've got it working now.
Allan
I'm having the opposite problem.
setFormatter
doesn't seem to be invoked when that field has an empty value.Here's how I figured out that
setFormatter
isn't being invoked:I can't see the
setFormatter
message from theerror_log
function in myphp_error.log
file, but I can see thegetFormatter
message.Can you show me the data being submitted by the client-side please? You'll be able to get that from the
Header
part of the Networking tab for that Ajax request.Allan