diff --git a/app/Config/CustomInputModifier.php b/app/Config/CustomInputModifier.php index 9bc709b..b593897 100644 --- a/app/Config/CustomInputModifier.php +++ b/app/Config/CustomInputModifier.php @@ -14,14 +14,18 @@ final class CustomInputModifier implements InputModifier { public static function modify(Control $input, IContainer $container): void { // we also have some inputs that are based on Nextras\FormComponents\Fragments\UIComponent\BaseControl if ($input instanceof BaseControl && $input->getName() === 'registry_address') { - $pairId = 'pair-' . $input->htmlId; - $input->setOption('id', $pairId); + $input->monitor(Form::class, function(Form $form) use ($input, $container): void { + // ID is not available until the Form is attached. + // Note: This will not handle re-attaching the form under different name but entries do not do that. + $pairId = 'pair-' . $input->htmlId; + $input->setOption('id', $pairId); - /** @var BaseControl */ - $country = $container->getComponent('country'); - $country->addCondition(Form::NOT_EQUAL, 46)->toggle($pairId, false); - $input->setRequired(false); - $input->addConditionOn($country, Form::EQUAL, 46)->setRequired(); + /** @var BaseControl */ + $country = $container->getComponent('country'); + $country->addCondition(Form::NOT_EQUAL, 46)->toggle($pairId, false); + $input->setRequired(false); + $input->addConditionOn($country, Form::EQUAL, 46)->setRequired(); + }); } } }