Forum Discussion

Claudius's avatar
4 years ago

Intercept editor form submission vs auto-save

Hi,

I'm trying to enhance our message post editor form with additional dropdown fields, including browser used. This information will be pushed to tags (could also use custom tags or even custom message metadata fields, but we went for the simple way using OOTB functionality).

My implementation challenge is intercepting the editor form submission event to populate the tag information and submit the form afterwards. I'm currently using code similar to below:  

<@liaAddScript>
  ;(function($) {
    var setupinfo = $('#dtk_setup_info').detach();
    $(setupinfo).insertAfter('.lia-form-attachments-fieldset-toggle');
  
    // Intercept form submission
  	$(".MessageEditorForm#form").submit(function(e){
  		e.preventDefault();
    	var form = this;
		
  	// Populate the "Tags" field with valid data from the dropdowns
        var tagPrefill = "";
        if ($( "#browser_used" ).val() != null) {
            tagPrefill += ", " + $( "#browser_used" ).val();
        }
        document.getElementById("lia-tags").value = tagPrefill;

        form.submit(); //delegate form submission event bypassing the jQuery bound event
    });

  })(LITHIUM.jQuery);
</@liaAddScript>

The issue I am facing is that the editor form's auto-save feature is actually als triggering a form submisson event. As a result any user who keeps the editor open long enough for the auto-save event to occur will have their message submitted unwantedly. I cannot find a way to tell apart a user-initated form submission from the auto-save one.

Any ideas?

  • VaibhavC's avatar
    VaibhavC
    Khoros Alumni (Retired)

    Claudius, you can use the following information to detect if the form submit is triggered due to an autosave action:

    The event target is an input element and its value is "Autosave". Also, a CSS class exists on this element like lia-button-Autosave-action.   

    The information from the event target which is an input element should help you identify if it is an autosave action.

    Please let me know if you have any questions.

     

    Thanks

    Vaibhav