How to Show a particular field when a dropdown item is changed?


In this example,, when the subscribe is changed the email field appears.

Instead of using a checkbox field, how would you do the same thing using a dropdown?

Sample code:
//The usuals:
require ‘…/atk/vendor/autoload.php’;
$app = new \atk4\ui\App(’ ');

$f_sub = $app->add(new \atk4\ui\Form([‘segment’]));
$f_sub->add([‘Label’, ‘Select Data type and add to Metric definition’, ‘top attached’], ‘AboveFields’);

$f_sub->addField(‘type’, [‘DropDown’, ‘caption’=>‘Data Type’, ‘values’ => [‘one’, ‘two’, ‘three’]]);

// Show email if dropdown labeled type has a value of ‘two’
//This does not work, what is the proper line of code here?
‘email’=> [‘type’=> ‘Single’],


Rules are based on Romantic ui Form validation rules

So in your case it should be;

'email' => ['type' => 'isExactly[0]'] // 0 being the index value 'one' in your Dropdown field

you may also use key value in your rule if you set Dropdown value using key.

$f_sub->addField(‘type’, [‘DropDown’, ‘caption’=>‘Data Type’, ‘values’ => ['one' => ‘One’, 'two' => Two’, ‘three’ => 'Three]]);

Then you can setup your rule as follow:

'email' => ['type' => 'isExactly[one]']