Hi there,
Need help with adding an additional confirmation pop up box if certain criteria met when user is trying to create or update a record.
Assuming that if "amount" field entered is equal or less than 0, then a confirmation box pop up asking if the user is sure of the value entered.
If user click OK, then proceed with creating or updating the record. If user click Cancel, then cancel the record creation or deletion to let user check the value again.
This pop up box should not appear if "amount" entered is more than 0.
Appreciate if someone can help with the js codes to be inserted in the hooks/tablename-dv.js file.
Thank you and have a nice day.
Zala.
Confirmation Pop Up Box
Confirmation Pop Up Box
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Confirmation Pop Up Box
Hi Zala,
I'm not a JS expert but I think something like below would work
I didn't actually try to run this, I may have some syntax error.
You could also google and experiment with the onchange event rather than the form insert/update if that would be a better experience.
Good luck.
~Paul
I'm not a JS expert but I think something like below would work
Code: Select all
function checkAmount()
{
// Check that the amount is > 0
var amount = $j('#amount').text(); // verify the control ID (#amount) by doing View Source
if ((amount != null) && (amount.trim().length > 0) && (parseInt(amount) > 0)) {
return 1;
}
return 0;
}
$j('#insert').click(function(){
if ( checkAmount() ) {
alert('Amount must be greater than 0');
}
})
$j('#update').click(function(){
if ( checkAmount() ) {
alert('Amount must be greater than 0');
}
})
You could also google and experiment with the onchange event rather than the form insert/update if that would be a better experience.
Good luck.
~Paul
Re: Confirmation Pop Up Box
Hi Paul,
Thanks for the guidance. I have managed to come out with the following codes in hooks/table_name-dv.js file.
Next, I need to figure out how to prevent the confirmation pop up box from appearing when I want to update the record (other field update) which already with 0 or negative premium value.
Again, thanks Paul for showing the light.
Zala.
Thanks for the guidance. I have managed to come out with the following codes in hooks/table_name-dv.js file.
Code: Select all
function show_error(field, msg) {
modal_window({
message: '<div class="alert alert-danger">' + msg + '</div>',
title: 'Error in ' + field,
close: function () {
$j('#' + field).focus();
$j('#' + field).parents('.form-group').addClass('has-error');
}
});
return false;
}
function show_error2(field) {
$j('#' + field).focus();
$j('#' + field).parents('.form-group').addClass('has-error');
return false;
}
/* on inserting or updating record, validate the Premium value */
$j('#update, #insert').click(function () {
/* Make sure premium, if provided, is numbers only and not empty */
var premium = $j('#premium').val();
if (isNaN(premium) || premium == '') {
return show_error('premium', 'Premium value should be numbers only and not empty.');
/* show confirmation pop up box if premium is less or equeal 0 */
} else if (premium <= 0) {
var result = confirm('Click OK to proceed with Premium value ' + premium);
if (result === true) {
return;
} else {
return show_error2('premium');
}
}
});
Again, thanks Paul for showing the light.
Zala.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Confirmation Pop Up Box
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.