prevent from being saved if an option is selected on radio button field and the next field is left blank

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

prevent from being saved if an option is selected on radio button field and the next field is left blank

Post by fgazza » 2021-05-26 20:02

Hi to all.
I need to prevent the record from being saved if the "other, please specify" option is selected in a radio button field and the next field named "other" is left blank.

In this case an error message "unable to save the record because you selected the OTHER option but did not specify in the next field.

Can anyone suggest the code?

Thank you!!!

Fabiano

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

Re: prevent from being saved if an option is selected on radio button field and the next field is left blank

Post by jsetzer » 2021-06-04 05:03

Seems you are looking for conditional validation: field2 is required IF field1 does not contain a certain value.

Alternative 1 (PHP)

Unset "required", re-generate app, then validate $data on serverside (PHP) in _before_insert and _before_update. Depending on the validation result, return TRUE or FALSE . Backdraw: if validation fails on insert and you return FALSE, user will be redirected and there may be data-loss.

Alternative 2 (Javascript)

Create a javascript function named TABLENAME_validateData(). Get the values of your fields by using Javascript/JQuery. Validate your fields' values. if validation fails, return false, otherwise return true. You can also highlight errors by adding Bootstrap's "has-error" class on the closest .form-group of the field which is causing validation errors.

(Done this few years ago but not tested with latest version)
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