postEdit returns empty $row

postEdit returns empty $row

we0038we0038 Posts: 39Questions: 13Answers: 1

for PHP library
Editor->on( 'postCreate', function ( $editor, $id, $values, $row )
$row works just fine. However,

Editor->on( 'postEdit', function ( $editor, $id, $values, $row )
$row is always empty while $values has only the edited values. What I need is some other values in the same row that set to be read only.

thanks.

This question has an accepted answers - jump to answer

Answers

  • we0038we0038 Posts: 39Questions: 13Answers: 1

    this was tricky.
    it turned out the reason is that I'm using both preEdit and postEdit
    where preEdit contains $editor->field( )->setValue( ); to set a value based on some logic.
    Still, the problem not solved yet. how can I use preEdit to set some value then work on postEdit row data?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    So if you use preEdit with the field()->setValue() the $row is completely empty in postEdit!? That absolutely should not be happening!

    Could you show me your code please?

    Thanks,
    Allan

  • we0038we0038 Posts: 39Questions: 13Answers: 1

    Hi Allan,
    my apologies.. you're right. my analysis wasn't correct

    it's all about the where condition. Once stage has been changed in preEdit, postEdit is useless in my case.

    ->where( 'stage', 1, '=' ) ->on( 'preEdit', function ( $editor, $id, $values){ $editor->field('stage')->setValue(2);}) ->on( 'postEdit', function ( $editor, $id, $values, $row ){...})

    My alternative solution now is removing preEdit and do update stage in postEdit using db()->update() method

    Thank you Allan

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Ah!

    There is also the writeEdit event which can be used like postEdit, but it is triggered before the libraries read data from the database, so you can modify the table's data before it is read.

    Allan

  • we0038we0038 Posts: 39Questions: 13Answers: 1
    Answer ✓

    cannot use that; $row is not available for writeEdit
    using db()->update() was sufficient for me.

    Thank you

This discussion has been closed.