Extend 'action' or customize request from Editor instance

Extend 'action' or customize request from Editor instance

rldean1rldean1 Posts: 141Questions: 66Answers: 1
edited December 2021 in Editor

I'm aware you can "extend" the data sent to the server inside Editor's ajax function. I've done it! $.extend(data, {...})

If I am outside the ajax function, and I wanted to extend the data, how could I do that?

For example, I want to set a custom action, or include extra data in the request... could I do it through the editor instance somehow?

// pseudo-code example:

            editor
                .create(false)
                .setAction('custom-action-name')
                .set('customFieldForDBProcessing', 420)
                .submit();

I think we must use edit, create, and delete. I want to do a specific sort of edit, but call it something like "upsert"..... but I want the fancy DT/DTE visual transition. Basically, the server needs to see it as an "upsert", but Editor should continue to treat it like an "edit".

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 56,819Questions: 1Answers: 9,029 Site admin

    It sounds like the initSubmit event is what you want.

    There is also preSubmit which lets you directly modify the data set to the server. The difference is that initSubmit would be used if you want to use the Editor API to set the values, while preSubmit is used after the data has been read from the form.

    Allan

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1
    edited December 2021

    @allan

    Those have been useful to me in the past. I later found these success/error callback functions for .sbumit() (below).

    Where are these submit callback functions processed (example below)? In the aforementioned events, submitError, or submitSuccess? If so, how do I pass in the callbacks shown below to wherever they are fired?

    I'd like to pass in parameters to these callbacks -- for example -- a reference to a modal that's on the screen, so I can close it. I think they take 1 param, which is the data that was received from the server. Can I add extra?

    Is there a better way to write this?

    // calling the editor reference from *outside* the editor 
    // add a flag to the data sent to SQL
    // if error occurs, disable button
    
    
                editor
                    .create(false)
                    .set('EmployeeID', EmployeeID)
                    .set('RetirementDate', RetirementDate)
                    .set('SessionID', SessionID)
                    .submit(
                        function (x) {
                            console.log( 'Form successfully submitted!' );
                            console.log('submit success callback', x);
                        },
                        function (y) {
                            console.log( 'Form  encountered an error :-(' );
                            console.log('submit fail callback:', y)
                            btnOk.innerHTML = "S**T!"
                        },
                        function (data) {
                            console.log('--submit method data', data)
                            data["previousEntryFlag"] = previousEntryFlag;
                            return data;
                        },
                        false);
    
  • allanallan Posts: 56,819Questions: 1Answers: 9,029 Site admin
    Answer ✓

    The callbacks are called immediately prior to their corresponding events. For example your success callback (first parameter passed into submit()) will be called just prior to the submitSuccess event.

    Generally I tend to use the events rather than the callbacks. It means you can submit in ways other than using the API (e.g. using KeyTable with inline editing).

    I'd like to pass in parameters to these callbacks -- for example -- a reference to a modal that's on the screen, so I can close it.

    You can't pass extra parameters into them. It is Editor that passes parameters into them.

    Instead you would have a reference to your modal and just call it there - e.g.:

    let myModal = new Modal(...);
    
    // ...
    .submit(
        function (x) {
            console.log( 'Form successfully submitted!' );
            console.log('submit success callback', x);
    
                    myModal.close();
        },
    

    Allan

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    @allan

    I think you are my most favorite coder on the planet.

    I have learned so much about JavaScript just in dealing with the DT/DTE framework.

    You are the best, Happy Holidays, and Cheers!

  • allanallan Posts: 56,819Questions: 1Answers: 9,029 Site admin

    Haha - thank you :).

    Happy Holidays!

    Allan

Sign In or Register to comment.