How to prevent editor open form?

How to prevent editor open form?

vincmeistervincmeister Posts: 136Questions: 36Answers: 4

Hi Allan,

I want to prevent open editor in some conditions.
I'm using editor.close() , but i think this is not smooth. Is there any way to prevent editor open ? Please advise, thank you

This question has accepted answers - jump to:

Answers

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited July 2017

    You can use the preOpen event. Returning false will stop the open operation.

    editor.on('preOpen', function(e, mode, action) {
        // Some logic
        return false;
    });
    
  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    @rduncecb thanks for the reply bu I don't want the editor open. If using return false, the form still open, but prevent update.

    Thanks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    @rduncecb is correct - preOpen can be used to stop the editor window from opening at all. Returning call from that event handler should stop the window from showing.

    Alternatively, you could use the optional second parameter of edit() to not show the form.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    Hi Allan,

    Here's my code. But return false not working to prevent form open. Please advise, thank you.

    editor.on('preOpen', function(e, mode, action) {
                editor.disable();
                var selected = table.row( { selected: true } );
                if ( selected.any() ) {
                    head_id = selected.data().activity_head.id;
                }
                $.get( "function/check_process_status.php",{ head_id: head_id}, function( d ) {
                    process_status = d;
                    console.log(process_status);
                    if (process_status == 1){
                        //editor.close();
                        return false;
                    }else if (process_status == 2){
                        now = moment().format('DD MMM YYYY / HH:mm:ss');
                        editor.field('start_time').val(now);
                        editor.field('activity_head.last_status').val(3);
                    }else if (process_status == 3){
                        now = moment().format('DD MMM YYYY / HH:mm:ss');
                        editor.field('finish_time').val(now);
                    }else if (process_status == 4){
                        //editor.close();
                        return false;
                    }
                });
            });
    
  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    Answer ✓

    It's not working because you're returning the value from the ajax callback, this does not return a value from your preOpen event handler, the end of the function is reached BEFORE your ajax call (and does not return a value) as the process is asynchronous.

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    @rduncecb thanks for the explanation. so how to make it happen? Please help thank you

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You would have to move the return false; to the preOpen event handler (i.e. line 23-24 above).

    You could then use open() to display the form if it should be shown in the Ajax handler.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    thanks @rduncecb & @allan for the explanation

This discussion has been closed.