Skip to content

Instantly share code, notes, and snippets.

@Idealien
Created February 17, 2018 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Idealien/77051f03ea91b5b17467d03d32b4b6f5 to your computer and use it in GitHub Desktop.
Save Idealien/77051f03ea91b5b17467d03d32b4b6f5 to your computer and use it in GitHub Desktop.
Gravity Flow - Confirmation dialog before form submit
(function (GravityFlowEntryDetail, $) {
$(document).ready(function () {
if( $('.gravityflow-step-user_input').length ) {
//User Input - Save Progress Button
if( $('#gravityflow_save_progress_button').length ) {
$('#gravityflow_save_progress_button')[0].onclick = null;
$('#gravityflow_save_progress_button').click(function() {
$('#action').val('update');
$('#gravityflow_status_hidden').val('in_progress');
if( $("#input_26_2").val() == '2.5') {
var confirmation = confirm("Are you sure you want to submit field 2 with a value of 2.5?");
if ( confirmation ) {
$("#form_26").submit();
} else {
return false;
}
}
});
}
//User Input - Submit Button
if( $('#gravityflow_update_button').length ) {
$('#gravityflow_update_button')[0].onclick = null;
$('#gravityflow_update_button')[0].click(function() {
$('#action').val('update');
$('#gravityflow_status_hidden').val('complete');
if( $("#input_26_2").val() == '2.5') {
var confirmation = confirm("Are you sure you want to submit field 2 with a value of 2.5?");
if ( confirmation ) {
$("#form_26").submit();
} else {
return false;
}
}
});
}
}
//Approval Submit
if( $('.gravityflow-step-approval').length ) {
if( $("button[name='gravityflow_approval_new_status_step_58']").length ) {
$("button[name='gravityflow_approval_new_status_step_58']").click(function() {
if ( $(this).val() == 'approved' && $(".entry-view-field-value:eq(0)").text() == '2.5' ) {
var confirmation = confirm("Are you sure you want to approve this entry with field 2 with a value of 2.5?");
if ( confirmation ) {
$("#form_22").submit();
} else {
return false;
}
}
});
}
}
});
}(window.GravityFlowEntryDetail = window.GravityFlowEntryDetail || {}, jQuery));
<?php
add_filter( 'gravityflow_enqueue_frontend_scripts', 'action_gravityflow_enqueue_frontend_scripts', 10 );
function action_gravityflow_enqueue_frontend_scripts() {
wp_enqueue_script( 'gf-confirm', plugins_url( 'assets/js/gf-confirm.js', __FILE__ ), array( 'jquery', 'gravityflow_entry_detail' ), '1.0.0', true );
}
?>
@bassata
Copy link

bassata commented Apr 6, 2018

The $("#form_XX") is not working. No matter which form I use, it will engage this script. Ideas?

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