setFormatter( Format::ifEmpty( null ) ) at the same time as a setValue
setFormatter( Format::ifEmpty( null ) ) at the same time as a setValue
I am doing a soft delete. For the most part i have followed this: https://editor.datatables.net/examples/api/softDelete
However, I want to set my time on the field server side. i.e. when I edit, I want the field to remain blank, but when I delete, I want it to set the current time. I have this on the server:
Field::inst('deleted_datetime' )
->setFormatter( Format::ifEmpty( null ) )
->setValue(date("Y-m-d H:i:s"))
It works for a delete (I send the client side datetime, but ignore it with the setValue option), but for a edit when I send a empty string from the client, it also sets the field value to the current date/time.
Does anyone know how to do this?
Answers
Yes, use the
preRemove
event to call thesetValue()
method only on delete.Allan
ta,
I think thats part of my issue though. Its not a Delete, its a soft-delete, which is essentially a edit. But I do not want to set it on a normal edit. How do I distinguish between a soft-delete edit and a normal edit?
I'm with you now. What you would need to do is check in the
preEdit
event handler if the user has submitted a soft delete action or not. If we take this example you would check to see ifusers.removed_date
is in the data submitted or not.Allan
love your work, thank you