Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update PlsPlusAddress required logic #55

Merged
merged 5 commits into from
May 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/components/PlsPlusAddress/PlsPlusAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class PlsPlusAddress extends FieldsetComponent {
enableManualMode: true,
input: true,
persistent: "client-only",
validate: {
required: true,
},
components: [
{
key: "addressData",
Expand Down Expand Up @@ -172,23 +175,6 @@ export class PlsPlusAddress extends FieldsetComponent {
return this.components || [];
}

addComponents(data = this.data, options = this.options) {
if (options.components) {
this.components = options.components;
} else {
const components =
this.hook(
"addComponents",
_.defaultsDeep(
this.componentComponents,
this.defaultSchema.components
),
this
) || [];
components.forEach((component) => this.addComponent(component, data));
}
}

mergeSchema(component = {}) {
let { defaultSchema } = this;
if (component.components) {
Expand Down Expand Up @@ -422,7 +408,7 @@ export class PlsPlusAddress extends FieldsetComponent {

renderElement(value) {
this.container?.getComponents().forEach((component) => {
if (!this.builderMode) {
if (!this.builderMode && this.attached) {
component.disabled =
component.originalComponent.disabled || !this.manualMode;
component.component.validate = !this.manualMode
Expand All @@ -440,11 +426,13 @@ export class PlsPlusAddress extends FieldsetComponent {
return this.onChange(flags, fromRoot);
};
});
if (!this.builderMode) {
if (!this.builderMode && this.attached) {
this.component.validate = {
custom: `valid = !!instance.address.selectedAddress;`,
customMessage: `${this.component.label} is required.`,
required: !this.manualMode,
...(this.originalComponent?.validate?.required && {
custom: `valid = !!instance.address.selectedAddress;`,
customMessage: `${this.component.label} is required.`,
required: !this.manualMode,
}),
};
}

Expand Down