preRemove validation

preRemove validation

KeepMovingKeepMoving Posts: 28Questions: 7Answers: 0

Hi,

Im trying to prevent to remove yourself from the list

->on( 'preRemove', function ( $editor, $id, $values) {
     $activeId=$values['usuario']['IdUsuario'];
     $sessionId=$_SESSION['IdUsuario'];
     if( $activeId== $sessionId){
        //then what? 

     }

} )

after validate how can I cancel or send a message to prevent deletion of that row?

Answers

  • allanallan Posts: 63,481Questions: 1Answers: 10,467 Site admin

    return false; will stop the row being deleted.

    However, perhaps a better way would be to have a validator on the IdUsuario field which you could run your check on. That way you can easily return an error message to the client-side.

    Allan

  • KeepMovingKeepMoving Posts: 28Questions: 7Answers: 0

    You mean something like this?

    editor.on('preRemove', function ( e, d ) {
                    var IdField = this.field( 'usuario.IdUsuario' );
                    if ( IdField.val() == 35 ) {
                        alert( 'No se puede eliminar este usuario' );
                        return false;
                    }
                
                    return true;
                } );
    
  • allanallan Posts: 63,481Questions: 1Answers: 10,467 Site admin

    That looks like Javascript rather than PHP. I had been meaning the PHP preRemove event like you had in your original code. Something like:

      ->on( 'preRemove', function ( $editor, $id, $values ) {
        $editor->validator( function ( $editor, $action, $data ) {
          ... some validator logic
        } );
      } )
    

    Allan

This discussion has been closed.