Skip to content

Instantly share code, notes, and snippets.

@jonvargas
Created January 25, 2015 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonvargas/9b887b465e272b38ccdf to your computer and use it in GitHub Desktop.
Save jonvargas/9b887b465e272b38ccdf to your computer and use it in GitHub Desktop.
/*
* Invokes que submission of the main task form, via a button placed outside the form.
* Also, requests for confirmation after the form validation passes correctly.
* @author: Jonathan Vargas
*/
function triggerTaskFormSubmit ()
{
// Finds required objects
var completeButton = jQuery ('button.btn-task-form')[0];
var mainTaskForm = jQuery('form.main-task-form');
// These elements will exist only on task forms
if (!completeButton || !mainTaskForm) {
return;
}
// Triggers submit when clicking Completar button
completeButton.onclick = function (e) {
// In case the button has another behaviour, like submit or href, ignores it
e.preventDefault ();
// Submits the form
mainTaskForm.submit ();
}
// After validation passed, ask the user to confirm the operation
mainTaskForm.on('beforeSubmit', function (e) {
// Request confirmation to submit form
if (!confirm("¿Está seguro de continuar? Esta operación dará por terminada la tarea actual y continuará el flujo restante del proceso"))
return false;
return true;
});
}
$(document).ready(function() {
triggerTaskFormSubmit();
});
@SupanutKetkul
Copy link

44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment