Validation help - In stock check

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
amminist
Posts: 2
Joined: 2023-08-30 15:41

Validation help - In stock check

Post by amminist » 2023-08-31 10:45

Hi
I would like to create a script to check if the order quantity is less than the quantity in stock and <500.
I have two tables
Product
ID
Description
Quantity in sotck (As calculated field from child Order - sum of quantity)
...

Order
ID
Product_ID
Quantity (int)
...

Image

thanks to udemy course i created a table-dv.js ( order-dv.js) to verify that the quantity does not exceed 500 ( and it works! :mrgreen: ) but i don't know how to get Quantity_in_stock.Product to compare with the entered quantity.order

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

$j(function(){
	$j('#update, #insert').click(function(){

		/* Quantity < 500 */
		var quantita = $j('#Quantita').val();



		if(isNaN(quantita) || quantita < 500 ){
			return show_error('Quantita', 'Inserire un numero < 500.');
		}


	});
})


Can anyone help me?


Ivan

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 1600
Joined: 2018-04-01 10:12

Re: Validation help - In stock check

Post by pböttcher » 2023-09-03 07:07

Hi,

at the time the user enters the Quantity (on change event) you could retrive the Quantity in stock via ajax and check if enough is available.
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.

fdissait
Posts: 18
Joined: 2019-07-24 07:57

Re: Validation help - In stock check

Post by fdissait » 2023-09-10 06:32

ok !
but how retrieve a look-up value from another table using ajax ?
I try several weeks without any success.
François

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 1600
Joined: 2018-04-01 10:12

Re: Validation help - In stock check

Post by pböttcher » 2023-09-12 18:50

Hi,
can you explain a bit detailled how your stucture looks like?
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.

amminist
Posts: 2
Joined: 2023-08-30 15:41

Re: Validation help - In stock check

Post by amminist » 2023-09-13 08:29

Same problem, do you know any site to understand the basics of ajax call in java script? I would like to understand and study how to create the call and how to use its result as a js variable.. Thanks
Ivan

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1725
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Validation help - In stock check

Post by jsetzer » 2023-09-13 11:47

W3schools has some nice tutorials:
https://www.w3schools.com/js/js_ajax_intro.asp

There is also help on Bootstrap, for example.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

Post Reply