use ->setValue() to store null
use ->setValue() to store null
I am using setValue() to store a date if certain criteria are met.
On edit, I want to change the date value back to a null, if the criteria no longer apply
if ( (Editor::action( $_POST ) === Editor::ACTION_CREATE) || (Editor::action( $_POST ) === Editor::ACTION_EDIT)) {
$returnedqualityvalue = $_POST['data']['tblitem']['ItemQualityID'];
if ($returnedqualityvalue == 3) {//if item is now a sale item, set the ItemDateonSale field to today
$SaleDateField
->set( Field::SET_BOTH )
->setValue( $today );
} else {
$SaleDateField
->set( Field::SET_BOTH )
->setValue( null );
}
}
i can put a date value for the 'else' block, and it works, but how do i use a null ?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Unfortunately a setValue of
null
means 'don't use the set value'! However, what you might be able to do (I've haven't actually tried it yet I'm afraid) is to use a closure function that will return null:Its a little underhand, but I think that should work...
Allan
works for me !