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
prevent from being saved if an option is selected on radio button field and the next field is left blank
Re: prevent from being saved if an option is selected on radio button field and the next field is left blank
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)
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools