PreEdit or PostEdit not working to setValue

PreEdit or PostEdit not working to setValue

hyklhykl Posts: 48Questions: 19Answers: 5
edited January 2017 in Editor

PreCreate is working !

->on('preCreate', function($editor, $values) {
            if (($values['field1'] + $values['field2'] + $values['field3'] + $values['field4']) > 29) {
                $_SESSION['user_who']['sumarization'] = "yes";
            } else $_SESSION['user_who']['sumarization'] = "no";
            
            $editor
                ->field('question')
                ->setValue($_SESSION['user_who']['sumarization']);
        })

PreEdit is not working :(

->on('preEdit', function($editor, $values) {
            if (($values['field1'] + $values['field2'] + $values['field3'] + $values['field4']) > 29) {
                $_SESSION['user_who']['sumarization'] = "yes";
            } else $_SESSION['user_who']['sumarization'] = "no";
            
            $editor
                ->field('question')
                ->setValue($_SESSION['user_who']['sumarization']);
        })

PostEdit is not working :(

->on('postEdit', function($editor, $values) {
            if (($values['field1'] + $values['field2'] + $values['field3'] + $values['field4']) > 29) {
                $_SESSION['user_who']['sumarization'] = "yes";
            } else $_SESSION['user_who']['sumarization'] = "no";
            
            $editor
                ->field('question')
                ->setValue($_SESSION['user_who']['sumarization']);
        })

Please you help and thank you very much :-)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    postEdit won't row because the value has already be set on the database. preEdit however should work. Could you show me your full PHP and also state what version of Editor it is that you are using please?

    Do you get any errors shown in the server's error log or anywhere else?

    Thanks,
    Allan

  • hyklhykl Posts: 48Questions: 19Answers: 5
    Answer ✓

    This is solved because I forget add to $id to preEdit - repaired:

    >on('preEdit', function($editor, $id, $values) {
                if (($values['field1'] + $values['field2'] + $values['field3'] + $values['field4']) > 29) {
                    $_SESSION['user_who']['sumarization'] = "yes";
                } else $_SESSION['user_who']['sumarization'] = "no";
                 
                $editor
                    ->field('question')
                    ->setValue($_SESSION['user_who']['sumarization']);
            })
    
This discussion has been closed.