Skip to content

Commit

Permalink
Fix: update billing address dynamic validation rules (#7172)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
jonwaldstein and Jon Waldstein authored Feb 1, 2024
1 parent ebc1309 commit 017a02c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ protected function createNodeFromDonorNameBlock(BlockModel $block): Node
}

/**
* @unreleased updated fields to add optional rules last so they can be dynamically validated.
* @since 3.0.0
*/
protected function createNodeFromBillingAddressBlock(BlockModel $block): Node
Expand Down Expand Up @@ -330,16 +331,16 @@ protected function createNodeFromBillingAddressBlock(BlockModel $block): Node
$group->getNodeByName('city')
->label($block->getAttribute('cityLabel'))
->placeholder($block->getAttribute('cityPlaceholder'))
->rules('max:255', new BillingAddressCityRule());
->rules('max:255', new BillingAddressCityRule(), 'optional');

$group->getNodeByName('state')
->label($block->getAttribute('stateLabel'))
->rules('max:255', new BillingAddressStateRule());
->rules('max:255', new BillingAddressStateRule(), 'optional');

$group->getNodeByName('zip')
->label($block->getAttribute('zipLabel'))
->placeholder($block->getAttribute('zipPlaceholder'))
->rules('max:255', new BillingAddressZipRule());
->rules('max:255', new BillingAddressZipRule(), 'optional');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function StateFieldContainer({
}

/**
* @unreleased Update city and zip components before rendering to display required asterisk
* @since 3.0.0
*/
export default function BillingAddress({
Expand All @@ -215,22 +216,25 @@ export default function BillingAddress({
const [cityRequired, setCityRequired] = useState(false);
const [zipRequired, setZipRequired] = useState(false);

const CityWithRequired = () => <City validationRules={{required: cityRequired}} />
const ZipWithRequired = () => <Zip validationRules={{required: zipRequired}} />

return (
<>
<fieldset>
{groupLabel && <legend>{groupLabel}</legend>}
<Country />
<Address1 />
<Address2 />
<City validationRules={{required: cityRequired}} />
<CityWithRequired />
<StateFieldContainer
apiUrl={apiUrl}
state={state}
setCityRequired={setCityRequired}
setZipRequired={setZipRequired}
nodeName={name}
/>
<Zip validationRules={{required: zipRequired}} />
<ZipWithRequired />
</fieldset>
</>
);
Expand Down

0 comments on commit 017a02c

Please sign in to comment.