Confirmation Pop Up Box

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Confirmation Pop Up Box

Post by zibrahim » 2020-06-14 16:13

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.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Confirmation Pop Up Box

Post by pfrumkin » 2020-06-14 18:05

Hi Zala,

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');
	}
})
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

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Confirmation Pop Up Box

Post by zibrahim » 2020-06-15 12:11

Hi Paul,
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');
		}
	}
});
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.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Confirmation Pop Up Box

Post by pbottcher » 2020-06-15 17:43

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.

Post Reply