how can I tell if the Editor instance that got opened is New, or Ed

how can I tell if the Editor instance that got opened is New, or Ed

aziegler3aziegler3 Posts: 47Questions: 11Answers: 1

I have this

        buttons: [
            { extend: 'create', editor: editor },
            { extend: "edit",   editor: editor }
        ]

next, I want to make some decisions on what to show and what not to show in an "edit" window,
I was trying to use something like this:

editor.on( 'open', function ( e, something) {
   if(something == 'xyz'){
       actions to hide fields
   }
} );

is there a parameter, value, property that I can find in the editor that I can evaluate to decide if this particular form is a "create" or an "edit"?
I saw this example, which uses the 'type', but that is the same for Create and Edit.

Thanks for any help on this.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,459Questions: 26Answers: 4,975

    The open has a parameter action that was introduced in 1.5. This will allow you to see if its a create, edit or remove operation.

    Kevin

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    You can also use mode() to determine what the editing mode is, or set the fields up as needed in separate initCreate and initEdit event handlers.

    Allan

  • aziegler3aziegler3 Posts: 47Questions: 11Answers: 1

    I need something like that what I need.
    Unfortunately, I am probably doing something wrong, because

        editor.on('open', function( mode, action) {
            console.log(action);
        });
    

    always evaluates to "main" regardless of opening the New, or the Edit buttons.

  • kthorngrenkthorngren Posts: 21,459Questions: 26Answers: 4,975
    Answer ✓

    Note that the open event has three parameters, for example:

    editor.on('open', function( e, mode, action) {
        console.log(action);
    });
    

    With your code action is referencing the second parameter which is mode.

    Kevin

  • aziegler3aziegler3 Posts: 47Questions: 11Answers: 1

    OMG! of course!
    Thanks, this is what i needed.

Sign In or Register to comment.