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?