Skip to content

Commit

Permalink
Merge pull request #1 from GuySartorelli/feat/small-changes
Browse files Browse the repository at this point in the history
Some code quality changes
  • Loading branch information
GuySartorelli authored Jul 11, 2023
2 parents 79f19a2 + 1df6657 commit 98971ea
Show file tree
Hide file tree
Showing 39 changed files with 262 additions and 221 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Any feature requests or recommendations should be raised as [an issue](https://g
This module adheres to [the Silverstripe module standards](https://docs.silverstripe.org/en/4/developer_guides/extending/modules/#module-standard)
Commit messages should be [semantic](https://seesparkbox.com/foundry/semantic_commit_messages), though the style used for this module differs from that reference in the following ways:

- The first letter after the commit type is capitalised.
- A fullstop is placed at the end of the commit message.
- The first letter after the commit type is capitalized.
- A full stop is placed at the end of the commit message.

Make sure you also read over [the resources docs](docs/en/00-resources.md) before committing any javascript.
72 changes: 48 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Thank you to [Signify](https://github.com/signify-nz) for making this module pos

This module probices a number of reusable composable validators (including AJAX validation) for use both in the CMS and in frontend forms.

Make sure you check out the [extensions documentation](docs/en/02-extensions.md) at a minimum - some of these should be applied in almost all projects using this module.
Make sure you check out the [extensions documentation][0] at a minimum - some of these should be applied in almost all projects using this module.

If your project has any automated client-side tests, or you are implementing a validator to be compatible with this module, please make sure you read the [client side tests documentation](docs/en/03-client-side-tests.md).
If your project has any automated client-side tests, or you are implementing a validator to be compatible with this module, please make sure you read the [client side tests documentation][1].

## Install

Install via [composer](https://getcomposer.org):
Install via [composer][2]:

```bash
composer require guysartorelli/silverstripe-composable-validators
Expand All @@ -22,35 +22,59 @@ composer require guysartorelli/silverstripe-composable-validators

The `AjaxCompositeValidator` adds a submit handler to your form. This doesn't always interact well with other submit handlers, and can result in either front-end validation being skipped or the form not submitting the way you expect it to, depending on which submit handler gets the event first. For best results, don't add additional submit handlers to the form.

If you're using the `AjaxCompositeValidator` on a form that uses [undefinedoffset/silverstripe-nocaptcha](https://github.com/UndefinedOffset/silverstripe-nocaptcha) 2.3.0 or higher, you should disable form submission handling for the `NocaptchaField` in that form (see instructions in the nocaptcha docs).
If you're using the `AjaxCompositeValidator` on a form that uses [undefinedoffset/silverstripe-nocaptcha][3] 2.3.0 or higher, you should disable form submission handling for the `NocaptchaField` in that form (see instructions in the nocaptcha docs).

## [Available Validators](docs/en/01-validators.md)
## [Available Validators][4]

- **[AjaxCompositeValidator](docs/en/01-validators.md#ajaxcompositevalidator)**
Subclass of [CompositeValidator](https://api.silverstripe.org/4/SilverStripe/Forms/CompositeValidator.html) that provides AJAX validation. Resolves [an issue with losing data](https://github.com/silverstripe/silverstripe-elemental/issues/764), faster turn-around for fixing validation problems, and provides a way to use the same validation for 'client-side' validation of frontend forms.
- **[SimpleFieldsValidator](docs/en/01-validators.md#simplefieldsvalidator)**
Ensures the internal validation of form fields by calling `validate` on them.
- **[RequiredFieldsValidator](docs/en/01-validators.md#requiredfieldsvalidator)**
Like Silverstripe's [RequiredFields](https://api.silverstripe.org/4/SilverStripe/Forms/RequiredFields.html) validator, but more convenient for use in a `CompositeValidator`.
- **[WarningFieldsValidator](docs/en/01-validators.md#warningfieldsvalidator)**
- **[`AjaxCompositeValidator`][5]**
Subclass of [`CompositeValidator`][6] that provides AJAX validation. Resolves [an issue with losing data][7], faster turn-around for fixing validation problems, and provides a way to use the same validation for 'client-side' validation of frontend forms.
- **[`SimpleFieldsValidator`][8]**
Ensures the internal validation of form fields by calling `validate()` on them.
- **[`RequiredFieldsValidator`][9]**
Like Silverstripe's [`RequiredFields`][10] validator, but more convenient for use in a `CompositeValidator`.
- **[`WarningFieldsValidator`][11]**
Displays a warning if some field(s) doesn't have a value. Useful for alerting users about data that is technically valid but may not provide the results they expect
- **[DependentRequiredFieldsValidator](docs/en/01-validators.md#dependentrequiredfieldsvalidator)**
Uses [SearchFilters](https://docs.silverstripe.org/en/4/developer_guides/model/searchfilters/) to define fields as required conditionally, based on the values of other fields (e.g. only required if `OtherField` has a value greater than 25).
- **[RequiredBlocksValidator](docs/en/01-validators.md#requiredblocksvalidator)**
Require a specific [elemental block(s)](https://github.com/silverstripe/silverstripe-elemental) to exist in the `ElementalArea`, with optional minimum and maximum numbers of blocks and optional positional validation.
- **[RegexFieldsValidator](docs/en/01-validators.md#regexfieldsvalidator)**
- **[`DependentRequiredFieldsValidator`][12]**
Uses [`SearchFilter`s][13] to define fields as required conditionally, based on the values of other fields (e.g. only required if `OtherField` has a value greater than 25).
- **[`RequiredBlocksValidator`][14]**
Require a specific [elemental block(s)][15] to exist in the `ElementalArea`, with optional minimum and maximum numbers of blocks and optional positional validation.
- **[`RegexFieldsValidator`][16]**
Ensure some field(s) matches a specified regex pattern.

### [Abstract Validators](docs/en/01-validators.md#abstract-validators)
### [Abstract Validators][17]

- **[BaseValidator](docs/en/01-validators.md#basevalidator)**
- **[`BaseValidator`][18]**
Includes methods useful for getting the actual `FormField` and its label.
- **[FieldHasValueValidator](docs/en/01-validators.md#fieldhasvaluevalidator)**
- **[`FieldHasValueValidator`][19]**
Subclass of `BaseValidator`. Useful for validators that require logic to check if a field has any value or not.

## [Traits](docs/en/01-validators.md#traits)
## [Traits][20]

- **[ValidatesMultipleFields](docs/en/01-validators.md#validatesmultiplefields)**
- **[`ValidatesMultipleFields`][21]**
Useful for validators that can be fed an array of field names to be validated.
- **[ValidatesMultipleFieldsWithConfig](docs/en/01-validators.md#validatesmultiplefieldswithconfig)**
Like ValidatesMultipleFields but requires a configuration array for each field to be validated.
- **[`ValidatesMultipleFieldsWithConfig`][22]**
Like `ValidatesMultipleFields` but requires a configuration array for each field to be validated.

[0]: docs/en/02-extensions.md
[1]: docs/en/03-client-side-tests.md
[2]: https://getcomposer.org
[3]: https://github.com/UndefinedOffset/silverstripe-nocaptcha
[4]: docs/en/01-validators.md
[5]: docs/en/01-validators.md#ajaxcompositevalidator
[6]: https://api.silverstripe.org/4/SilverStripe/Forms/CompositeValidator.html
[7]: https://github.com/silverstripe/silverstripe-elemental/issues/764
[8]: docs/en/01-validators.md#simplefieldsvalidator
[9]: docs/en/01-validators.md#requiredfieldsvalidator
[10]: https://api.silverstripe.org/4/SilverStripe/Forms/RequiredFields.html
[11]: docs/en/01-validators.md#warningfieldsvalidator
[12]: docs/en/01-validators.md#dependentrequiredfieldsvalidator
[13]: https://docs.silverstripe.org/en/4/developer_guides/model/searchfilters/
[14]: docs/en/01-validators.md#requiredblocksvalidator
[15]: https://github.com/silverstripe/silverstripe-elemental
[16]: docs/en/01-validators.md#regexfieldsvalidator
[17]: docs/en/01-validators.md#abstract-validators
[18]: docs/en/01-validators.md#basevalidator
[19]: docs/en/01-validators.md#fieldhasvaluevalidator
[20]: docs/en/01-validators.md#traits
[21]: docs/en/01-validators.md#validatesmultiplefields
[22]: docs/en/01-validators.md#validatesmultiplefieldswithconfig
Loading

0 comments on commit 98971ea

Please sign in to comment.