This topic is locked

Required fields according to other dependent fields

9/28/2022 3:48:52 PM
PHPRunner General questions
A
alfonso authorDevClub member

I have a mandatory field called "country" (lookup wizard with all countries) and another mandatory field that is "province". This is a "lookup wizard" type field, but only with the provinces of Spain. If the country Spain is chosen, then the provinces of Spain appear in the second field. And it is mandatory to complete it. But if any other country is chosen, there are no options available in the province field, so, being a mandatory field, it does not allow us to complete the registration.
Any ideas?

Admin 9/28/2022

You can make a field/control to be required or not required using Javascript API. Use addValidation() function.

Btw, Google search for "phprunner make field required" makes wonders.

A
alfonso authorDevClub member 9/28/2022

Thanks. Do you mean I must put the code in Events -> (table_name) -> Edit -> Javascript Onload Event?

A
alfonso authorDevClub member 9/28/2022

I've got it with:

var F1 = Runner.getControl(pageid, 'residencia');
var F2 = Runner.getControl(pageid, 'provincia_id');
var F3 = Runner.getControl(pageid, 'nombre');
F1.on('change', function(e)
{
if (this.getValue() == 'Albania')
{
F2.removeValidation("IsRequired");
F3.setValue("None");
}
else
{
F2.addValidation('IsRequired')
}
});

But although the F2 field is no longer mandatory, the asterisk still appears in the label and can generate doubts
Another possible solution would be to fill in that field with a value, but since it is a "lookup wizard" type field with predefined values, it doesn't let me do it.

Admin 9/28/2022

You can always use a different type of a lookup wizard, i.e. AJAX list page with search