How to have a MOQ conditional logic?

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

How to have a MOQ conditional logic?

Post by urichard » 2022-11-27 13:52

Hi,

How do i prevent a submit button to be pressed unless it meets the minimum required quantity?

For example: Lets say the Hospital has a MOQ (minimum order quantity) and before the order can be placed for all the items the conditional logic (either in the SQL or not sure where) needs to check if it meets the MOQ of the hospital before it can be successful submitted?

Thanks for the help

Kind Regards,
Richard
[email protected][/color]

Kind Regards
Richard

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

Re: How to have a MOQ conditional logic?

Post by pbottcher » 2022-11-28 21:43

Hi,

you can add an additional hidden field to your form (unless you have it as e.g. readonly information) for the MOQ.
Then you register for the SAVE request and check if the MOQ is reached, if not you do not save the record with an adequate message to the user.

Note that you also need to check on the server-side as a client check may not be sufficient.

Hope that gives you a starting point.
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.

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: How to have a MOQ conditional logic?

Post by urichard » 2022-12-06 18:31

Thanks pböttcher

Do you have example code for me just to help to get started in the right direction please?
[email protected][/color]

Kind Regards
Richard

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

Re: How to have a MOQ conditional logic?

Post by jsetzer » 2022-12-06 18:51

There are many ways to solve this. Here is just one example as a starting point.

Code: Select all

// file: hooks/TABLENAME-dv.js
function myCustomValidation() {
    // check your conditions here
    // do alerts or whatever you want to indicate
    alert("no!");
    // return false if you want to cancel update
    return false;
}

jQuery("#update").on("click", function() {
    return myCustomValidation();
});
Another solution would be hooking into change event of form, do your custom validation, perhaps disable #update (or #insert) button, show notifications or a combination of both. pböttcher is completely right: Never trust user input. You will need additional serverside validation for example in before_update hook.
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

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply