Editor presubmit event

Editor presubmit event

david.j.meyer2@boeing.comdavid.j.meyer2@boeing.com Posts: 54Questions: 15Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I want different logic in the presubmit event depending on the type of edit being performed. If the user does a bubble edit on a column i want to ignore all the logic in the presubmit event. If the user edits the entire record in the editor dialog I want the logic to execute in the presubmit event.

How do i determine which action the presubmit came from.

        editor.on('preSubmit', function (e, o, action) {
            // if in edit mode and not a bubble event
            if (action == 'edit') {
                // Execute some code if not a bubble submit
                }

                // If any error was reported, cancel the submission so it can be corrected
                if (this.inError()) {
                    return false;
                }
            }
        });

The parameters in the function do not seem to provide access to the initiating event type. (bubble, dialog)

thanks, Dave

Answers

  • david.j.meyer2@boeing.comdavid.j.meyer2@boeing.com Posts: 54Questions: 15Answers: 0

    I have resolved my issue. If there is a better way then I have implemented, please provide me some insight.

    I accomplished the change by turning off the preSubmit prior to launching editor.bubble. I then use the closed event to determine if the type was a bubble, if it was i redefine the preSubmit event.

    I have included the outline of the code below.

            editor.on('closed', function (e, type) {
                // if its a bubble event i have to redefine the preSubmit action
                if (type == 'bubble') {
                    // redefine the preSubmit action on the editor
                    editor.on('preSubmit', function (e, o, action) {
                        // If editing do some checking
                        if (action == 'edit') {
    
                            }
    
                            // If any error was reported, cancel the submission so it can be corrected
                            if (this.inError()) {
                                return false;
                            }
                        }
                    });
                }
            });
    
            $('#Table').on('click', 'tbody td', function (e) {
                if ($(this).index() == 4 || $(this).index() == 13) {
                    // if its a column i can bubble edit, disable presubmit checks
                    editor.off('preSubmit');
                    editor.bubble(this);
                }
            });
    
  • david.j.meyer2@boeing.comdavid.j.meyer2@boeing.com Posts: 54Questions: 15Answers: 0

    Almost forgot you have to define the preSubmit event on page load too. So its present if the first event is an edit not a bubble.

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

    I'd use display() in your preSubmit event handler to find out what kind of edit is being performed.

    Allan

  • david.j.meyer2@boeing.comdavid.j.meyer2@boeing.com Posts: 54Questions: 15Answers: 0

    To help anyone else looking for this type of implementation I came up with a different solution. I created a JavaScript boolean variable that i default to false. I then set the variable to true if the event fired is a bubble event. That way when the preSubmit validation happens i can use that to determine what validation is required for the edit type event. This allows me to have different messaging when bubble editing then full editor dialog edit. I have included the code below. I modified the code so i could post it but it should give you an idea.

        var IsBubbleEditType = false;
    
        editor.on('closed', function (e, type) {
            if (IsBubbleEditType) {
                IsBubbleEditType = false;
            }
        });
    
        $('#prReportTable').on('click', 'tbody td', function (e) {
            bubbleIndex = "";
            if ($(this).index() == 2 ||$(this).index() == 4 || $(this).index() == 13) {
                //editor.off('preSubmit');
                IsBubbleEditType = true;
                bubbleIndex = $(this).index();
                editor.bubble(this);
            }
        });
    
        // Prepare to submit
        editor.on('preSubmit', function (e, o, action) {
            if (action == 'edit') {
                var STATUS = this.field('STATUS');
                var ID = this.field('ID');
                var BVF_NUMBER = this.field('BVF_NUMBER');
    
                // Only validate user input values - different values indicate that
                // the end user has not entered a value
                if (IsBubbleEditType) {
                    if (!STATUS.isMultiValue() && bubbleIndex == 4) {
                        if (STATUS.val() == "" && ID.val() == "") {
                            STATUS.error('A STATUS is "" then  ID must be given value!');
                        } else if ((STATUS.val() == "" || STATUS.val() == "IN WORK") && ID.val() == "") {
                            STATUS.error('A STATUS is "" then  ID must be given value!');
                        } else if ((STATUS.val() != "" && STATUS.val() != "IN WORK") && ID.val() == "") {
                            STATUS.error('ID must be cleared with status of "EXCLUDE", "NOT APPLICABLE" or "NOT WORKED"!');
                        }                         }
                } else {
                    if (!STATUS.isMultiValue()) {
                        if (STATUS.val() == "" && ID.val() == "") {
                            ID.error('A BVF_NUMBER must be given with status of ""!');
                            STATUS.error('A STATUS is "" then  ID must be given value!');
                        } else if ((STATUS.val() == "" || STATUS.val() == "IN WORK") && ID.val() == "") {
                            ID.error('A ID must be given with status of "" or "IN WORK"!');
                            STATUS.error('A STATUS is "" then  ID must be given value!');
                        } else if ((STATUS.val() != "" && STATUS.val() != "IN WORK") && ID.val() != "") {
                            ID.error('ID must be cleared with status of "EXCLUDE", "NOT APPLICABLE" or "NOT WORKED"!');
                            STATUS.error('A STATUS is "EXCLUDE", "NOT APPLICABLE" or "NOT WORKED" then  ID must be cleared!');
                        }                 
                    }
                }
                // If any error was reported, cancel the submission so it can be corrected
                if (this.inError()) {
                    return false;
                }
            }
        });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Nice! Thanks for sharing this with us.

    Allan

Sign In or Register to comment.