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

Support Client-Side Validation #16

Closed
dillonredding opened this issue Jan 25, 2023 · 0 comments · Fixed by #38
Closed

Support Client-Side Validation #16

dillonredding opened this issue Jan 25, 2023 · 0 comments · Fixed by #38
Assignees
Labels
enhancement New feature or request

Comments

@dillonredding
Copy link
Member

When submitting an action, there should be an option to enable/customize client-side validation.

abstract class ValidationResult;

class PositiveValidationResult extends ValidationResult;

class NegativeValidationResult extends ValidationResult {
  invalidFields: Field[];
}

type Validator = (fields: Field[]) => ValidationResult;

// custom validator
await submit(action, {
  validator: (fields: Field[]): ValidationResult => {
    const invalidFields: Field[] = [];
    // validate fields (e.g., based on `type`)
    return invalidFields.length > 0
      ? new NegativeValidationResult(invalidFields)
      : new PositiveValidationResult();
  }
});

// disable validation
await submit(action, { validate: false });

By default, we could provide a default validator that functions similar to HTML's client-side validation.

@dillonredding dillonredding added enhancement New feature or request good first issue Good for newcomers labels Jan 25, 2023
@dillonredding dillonredding removed the good first issue Good for newcomers label Jun 4, 2023
@dillonredding dillonredding self-assigned this Sep 2, 2023
dillonredding added a commit that referenced this issue Sep 2, 2023
@dillonredding dillonredding linked a pull request Sep 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant