Problem with 'required' in custom_required_functions.php

Matthijs

Member
Hi, I use the code below in custom_required_functions.php

If I use the function "dadabik_hide_nsd_opduwer" on a select_single_radio field, the field is correct hidden/shown.
But the "required" option does not work: if $a['required'] = true; - it is possible to save the record without selecting one of the values (and thus have a NULL in the database).


function dadabik_hide_nsd_opduwer ($params){
if ( $params['deelnemen'] <> 'Ja' or $params['type_boot'] <> 'Opduwer')
{
$a['show'] = false;
$a['required'] = false;
}
else{
$a['show'] = true;
$a['required'] = true;
}
return $a;


Your current DaDaBIK version​

You are using DaDaBIK version 11.12-Elba enterprise, installed on 10-12-2023 (installation code: 18828644e443ac0e33), the latest version of DaDaBIK is 11.12-Elba released on 30-11-2023

You are running the latest release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enterprise to Platinum) please contact us.

System info​

PHP Version: 7.4.33

mysql version: 5.5.5-10.6.16-MariaDB

Web server: Apache/2

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
 

darren

Member
If i am understanding this correctly, you have a radio field that hides unless the user selects 'ja' or 'opduwer'. if they do, a radio field appears and is supposed to be required to fill out, however, the radio field is appearing but is not showing as being required?
 

Matthijs

Member
Hi,

if field deelnemen = 'Ja' and type_boot = 'Opduwer', I want to show a radio field.
The field is displayed correctly, but I can finish editing the record without selecting one of the radio values. So, field stored as NULL.
I would expect since I say $a['required'] = true that I would need to select a value!

thanks for any help!
Matthijs
 

darren

Member
your response seems to disagree with your code if you want the radio to be require if deelnemen = 'Ja' and type_boot = 'Opduwer' then $params['deelnemen'] <> 'Ja' or $params['type_boot'] <> 'Opduwer' would not get you that. and should be $params['deelnemen'] == 'Ja' and $params['type_boot'] == 'Opduwer'.

your existing code would become required if either Ja or Opduwer is selected, in case thats not what you are going for. Just to make sure you are missing a closing } in your code, also maybe try defining $a as $a = array() earlier in your function because it is not apparent to me what is wrong with your code. maybe something elsewhere in the code
 

Matthijs

Member
Hi Darren,

closing } was there. I also tried $a = array() -> but no effect.
The code works fine for a text field. Bit not for a radio field ...
 

Matthijs

Member
I found the solution in the manual:

For select_single_radio fields, if the user didn't select any option, the corresponding key in $parameters_ar won't be set
and
if you need to use a field value, the correspondent field cannot be disabled in the edit form and cannot be a calculated field (which is always disabled)

So the fields I was comparing were not set ...
 
Top