Created
January 25, 2015 01:27
-
-
Save jonvargas/9b887b465e272b38ccdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
44