Skip to content

Commit

Permalink
add safety checks for required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SalihuDickson committed Nov 25, 2024
1 parent ce7b4d7 commit add8279
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/ecc-utils-design/src/components/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,19 @@ export default class EccUtilsDesignForm extends LitElement {
if (field.type === "array") {
return this.renderArrayTemplate(field, newPath);
}
if (field.type === "switch") {
return this.renderSwitchTemplate(field, newPath);
}

if (field.fieldOptions?.required) {
if (
!_.get(this.form, newPath) &&
!this.requiredButEmpty.includes(field.key)
) {
// add to requiredButEmpty

// eslint-disable-next-line no-empty
if (!this.hasUpdated && field.fieldOptions.default) {
} else this.requiredButEmpty.push(field.key);
if (this.hasUpdated || !field.fieldOptions.default) {
this.requiredButEmpty.push(field.key);
}
} else if (_.get(this.form, newPath)) {
// remove from requiredButEmpty
this.requiredButEmpty = this.requiredButEmpty.filter(
Expand All @@ -582,9 +584,6 @@ export default class EccUtilsDesignForm extends LitElement {
}
}

if (field.type === "switch") {
return this.renderSwitchTemplate(field, newPath);
}
return this.renderInputTemplate(field, newPath);
}

Expand Down

0 comments on commit add8279

Please sign in to comment.