setValue() to 0
setValue() to 0
On Editor::ACTION_EDIT I am trying to setValue of a database (decimal) field to 0, if certain criteria are met,- but it stubbornly refuses.
Any other value is fine
if ( Editor::action( $_POST ) === Editor::ACTION_EDIT ) {
$returnvalue = $_POST['data']['tblorderdetails']['Returned'];
if ($returnvalue == 1) {//if item is returned, set the ReturnedDate field to today, set the PatronPayment field to 0
$dateField
->set( Field::SET_BOTH )
->setValue( $today );
$patronpaymentField
->set( Field::SET_BOTH )
->setValue( 0.01 );
}
}
if i setValue(0.01) to my field, (or any other numerical value, including negative values) the table is updated, but 0 does not update
(Using editor 1.4.0)
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
In the Field.php file on line 458 (in the
apply
method) you found find:Could you change it to be:
please? I think that should address the issue.
Regards,
Allan
Unfortunately, that doesn't make a difference,
Odd - I've just tried it and it appears to work as expected. Can you show me your full PHP and also a schema dump for the DB table?
Allan
ok,
table
php
I don't understand that I'm afraid. With the change I suggested above your code looks like it should be working perfectly.
We'll need to add some debug statements in to figure out what is happening. On line 546 you will find:
Immediately before it add:
it will cause a JSON error, but when you look at the JSON return in your browser you should be able to see what Editor is trying to use as a value for the field.
Allan
OK, apologies, I made a mistake.
In the process of updating datatables to 1.10.5, I neglected to change the path on my page, so it was still pointing to 1.10.4.
Let me do that again...
I can confirm that changing line 458 in Fields.php to
does indeed fix the problem with setting the value of PatronPayment to 0, however it causes a different one.
Now the values in 2 other fields are cleared on edit
The DetailPrice field is set to NULL and the DetailSKU to empty string
Using the code you supplied to debug, the json returned is as follows...
Odd! Can you show me the values that are being submitted by the client-side please? You'll be able to find them in the "Headers" of the Ajax request made in your browser's developer tools.
Allan
i can confirm that if line 458 in Fields.php reads...
the row is updated fine, with the exception of when 0 is the value
if i change line 458 to
0 is updated OK, but the two fields mentioned above are set to NULL and ""
Headers info (extract)...
One thing I haven't done in the json is explicity ->set( Field::SET_NONE ); for these fields, but as the issue doesn't occur otherwise, i didn't think it necessary, (these fields do not appear in the editor instance)
That's not quite right. It should be:
as I have above. That would probably explain the problem since the logic is being inverted!
Allan
My bad.
IATD.
Thanks Allan