{"_id":"@absaldanha/stimulus-form","_rev":"2-d3f315b2e8eb36b817701601d5b1dcf6","name":"@absaldanha/stimulus-form","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.1":{"name":"@absaldanha/stimulus-form","version":"0.0.1","license":"MIT","author":{"name":"Alexandre Saldanha"},"repository":{"type":"git","url":"git+https://github.com/absaldanha/stimulus-form.git"},"types":"dist/types/index.d.ts","main":"dist/stimulus_form.umd.js","module":"dist/stimulus_form.js","scripts":{"types":"tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types","build":"yarn types && rollup -c --bundleConfigAsCjs","dev:clear":"rm -r cypress_app/node_modules","dev:install":"cd cypress_app && yarn install","dev":"cd cypress_app && yarn vite","test":"jest","test:cypress":"cypress run","prerelease":"yarn build && npm pack --dry-run","release":"yarn publish --access=public"},"devDependencies":{"@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.0.1","@rollup/plugin-terser":"^0.2.1","@rollup/plugin-typescript":"^10.0.1","@testing-library/dom":"^8.19.0","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.2.4","cypress":"^12.1.0","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","rollup":"^3.7.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.3"},"dependencies":{"@hotwired/stimulus":">= 3.2"},"description":"A simple form validation library for the `<form>` you already have.","licenseText":"MIT License\n\nCopyright (c) 2022 Alexandre Saldanha\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@absaldanha/stimulus-form@0.0.1","dist":{"shasum":"7226abb4dd28064bc4ec4f68486626dcd00079ad","integrity":"sha512-Rk+SRncwQjU3LNJbbk7GSeACeKChICr31rfyEQg1IrgLBDmiB+ijMmD+GBH2Fh5Be8m54JTcL9YaxnA0YZUKlQ==","tarball":"https://registry.npmjs.org/@absaldanha/stimulus-form/-/stimulus-form-0.0.1.tgz","fileCount":37,"unpackedSize":87775,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnmzi+A/MkBylXf6l6LjNn9mMXhdSEmXY6SQJ9LPp/KwIgKvelXxznXD5Xfk+tBHlH9yRoeLVsWw2yyqgn136uzPU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj5s/8ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpAfxAAoHlT8IdwTA5gXDCtovBTrNaKkJ6iEDOmK115xe17NDxAkAZ/\r\nR67kqtQ/2y50KOMqMfGwQ5+xXbnv5esRpGA4/BG2bRVSVcrST1YxkkrnhDmI\r\nxj+aFzMfFTQGt8RGHtEy1MHj5/c78jEM+YiBQ6MF6azfNId6zQX+PcTU7z1K\r\nFmnMN7H62wA6JLACNc+M26PH0iUve8plpj0utDcz2ypYqVCrg8TD4GnFjUI7\r\naU8AS0pj7P1wld6LXRJKdBwb1P8Ip+DjWc7PFmhvche0jqpxejLqe05FceRZ\r\nmYK9jorOcMJsKQuesb9NecXdOdQGrR8ojACB0xE2MSyQrZqSptd2Ko+hBKX5\r\nA/QbxWmrL1istrDISQbFpD/V/H7HlZ81d3Y8bhJ2tR13NMxlct40n+UiwBHf\r\nZ3osMbuQ3y92NlxRW10UepkmXk1o+NuwB4F+fNKRPm26qgSasIuOtK1tpkju\r\nPMaMKsYyxagwChmB+HWt8M2ZCFM3wVoTncBJJYYYvTmgn32uYUFq5vFWrK9A\r\ntD6YHEDpKCmBE2wv0OxDx52uTmQS/yQNP0uIjVCu02JGERTrljrYOnTaDrYw\r\nA+ivFPG9P6fMgUywIxPokZ7p1ROyp+2BC/aNqzFEU+/HZ8vBaiT1kYtWfXs4\r\ndi2x6VeTPY7C0esaBQiFOjQimDD5BbpqSs4=\r\n=X2fe\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"absaldanha","email":"absaldanha@protonmail.com"},"directories":{},"maintainers":[{"name":"absaldanha","email":"absaldanha@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stimulus-form_0.0.1_1676070908050_0.8245715314973308"},"_hasShrinkwrap":false},"0.0.2":{"name":"@absaldanha/stimulus-form","version":"0.0.2","license":"MIT","author":{"name":"Alexandre Saldanha"},"repository":{"type":"git","url":"git+https://github.com/absaldanha/stimulus-form.git"},"types":"dist/types/index.d.ts","main":"dist/stimulus_form.umd.js","module":"dist/stimulus_form.js","scripts":{"types":"tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types","build":"yarn types && rollup -c --bundleConfigAsCjs","dev:clear":"rm -r cypress_app/node_modules","dev:install":"cd cypress_app && yarn install","dev":"cd cypress_app && yarn vite","test":"jest","test:cypress":"cypress run","prerelease":"yarn build && npm pack --dry-run","release":"yarn publish --access=public"},"devDependencies":{"@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.0.1","@rollup/plugin-terser":"^0.2.1","@rollup/plugin-typescript":"^10.0.1","@testing-library/dom":"^8.19.0","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.2.4","cypress":"^12.1.0","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","rollup":"^3.7.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.3"},"dependencies":{"@hotwired/stimulus":">= 3.2"},"description":"A simple form validation library for the `<form>` you already have.","licenseText":"MIT License\n\nCopyright (c) 2022 Alexandre Saldanha\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@absaldanha/stimulus-form@0.0.2","dist":{"shasum":"fe99cbc659f05de7397415dff5275958f51ae122","integrity":"sha512-Q/U7AezR+tVuZ+dN4MwA07xQohwkO+sNgTSLNa7MtzhKpSgwamanL8jEE8CVqBh4872hng1MljWt7gTM5yTCzQ==","tarball":"https://registry.npmjs.org/@absaldanha/stimulus-form/-/stimulus-form-0.0.2.tgz","fileCount":37,"unpackedSize":55105,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBWv3nzaxJvix9/HwEq2mNGCUoz6Iov48+w39tojQhq7AiAkTSdX4fLUim1ncxBmU+f3ay6jJquVClMCJbuknSnwWw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj6FmIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmpvwg/9GCddvEN8wZZrq4vvtswxmBGSPOZ+NFo1JTnxMkHuU1fZUcpP\r\nDl+3YyPdrDHLmRGP4LGQqE4TGXciYaPbQ2uJYl86pcTEhXwpaX06TFvrR8Zt\r\nFRCPN4fG7qCX6mIN11brmigNM3fhyLo9oRPT01hQrd9Qev9VSYr5f5yRlilu\r\nGFZ+pHeE9QW6W20+V/A16CzagrZxLCYClnBgevHvvRq3uhoqjJV6f9pKw/Ev\r\ntaNtsk5WM3Kkx8i4tT6BswLarD29/uupbvsYlhU9jEKZKyp74GFvxyCDE3m8\r\nw9+i44IVdC3kV7fS/C191NPs/yYiUaYIoyqmY4r6zGS3pRAb+huMGM+I0NnV\r\nMOo+X3ZNM7885Vc0WSL14VxmGL2GjH8imuuSPexUyB31RRWz6EIz6Ql/Kyq4\r\nB+Nyq1O3DRdj780G2SZPbujmXhY0YIh/naIKZiboG7bhQVQpZcuXRDtq5S1Y\r\nifrOAkfMJZC4lh4cH8acFhWdv2cYcWaEW3otuR+2tXDq1Gi1o9pSTrVMe/V9\r\nP2SH/HgJQH8b1ph4fZS6GSZhl94scCKfMxR18vh7CK4BiO83vUphrklPngOh\r\nReMJLXFYRiUYkWmDZtEIzTC7iw0TX5Btyfpog+7EK1pxru7Jscn6W5fFyooK\r\nTUxWB2bC/X0tNC8uddb7CdkwKyn8WuM1VYM=\r\n=Bwq0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"absaldanha","email":"absaldanha@protonmail.com"},"directories":{},"maintainers":[{"name":"absaldanha","email":"absaldanha@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stimulus-form_0.0.2_1676171656443_0.6218294498638064"},"_hasShrinkwrap":false},"0.0.3":{"name":"@absaldanha/stimulus-form","version":"0.0.3","license":"MIT","author":{"name":"Alexandre Saldanha"},"repository":{"type":"git","url":"git+https://github.com/absaldanha/stimulus-form.git"},"types":"dist/types/index.d.ts","main":"dist/stimulus_form.umd.js","module":"dist/stimulus_form.js","scripts":{"types":"tsc --noEmit false --declaration true --emitDeclarationOnly true --outDir dist/types","build":"yarn types && rollup -c --bundleConfigAsCjs","dev:clear":"rm -r cypress_app/node_modules","dev:install":"cd cypress_app && yarn install","dev":"cd cypress_app && yarn vite","test":"jest","test:cypress":"cypress run","prerelease":"yarn build && npm pack --dry-run","release":"yarn publish --access=public"},"devDependencies":{"@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.0.1","@rollup/plugin-terser":"^0.2.1","@rollup/plugin-typescript":"^10.0.1","@testing-library/dom":"^8.19.0","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.2.4","cypress":"^12.1.0","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","rollup":"^3.7.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.3"},"dependencies":{"@hotwired/stimulus":">= 3.2"},"description":"A simple form validation library for the `<form>` you already have.","licenseText":"MIT License\n\nCopyright (c) 2022 Alexandre Saldanha\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@absaldanha/stimulus-form@0.0.3","dist":{"shasum":"3f38d3c4d58c6d681c7e661ad6b7542eb6be3700","integrity":"sha512-5GplLKyQNJNBKjF/DHWcy+KqSd/nrl8X87dcFZLdN8P0Fbgz9PTwxZKBQz0BZzyB5lngRAn4gfOk3UdbUEn2xw==","tarball":"https://registry.npmjs.org/@absaldanha/stimulus-form/-/stimulus-form-0.0.3.tgz","fileCount":37,"unpackedSize":55101,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCKgkiyGmZyhLQbW38yLItJbOthzsA6oB9gbCkJYNl4agIhAIX99iN857ShKUw8mA6UVuuoop1/G4DPtyDrmEtuhDn3"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkDQwxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoUyA//fTErKeGGsqSMexD0SyB3YVZSNg1bBFcA+0+sUqplQ+oqN1BZ\r\n7gzlIRphwy+GJOGCo1g/W2JGXTL7svrfvyeW7iE8E49HxZMT+0OKY5s1/bVO\r\nWabXYF7EDVcFLhda3VvtcVU+CukqfeOzODEPmBfaNZ2oxqZtUzk3w7wYqRf5\r\nezj2iSpmY2A+S7fgXCc4E2O+a5fs7S4CQ9sI5//w5CbF9e6i6PeUkvuhmC54\r\nnWC6/CBL3AhSJTfGT7HK+05GPTTDbSFsb1b6JitpuPDipzVPuvzpbxwZd2OB\r\nZXFICGcT48P57VRxntBomqDAiIyEMM894pM5eg0cIOwMASw+GijXuhsff4MN\r\no3XH4nbGcSnm3uChyzSQ6ctsxCrIIoqBStHOt2tFdbzoPM2JFjRVPfNgys63\r\nqJunYKkFQP3xRamAksKPeZXJ0Rozdbn5f3ByVA6ypAjKGIjf8KMqRReMPI0l\r\nKIY8ucQ4/aM3PexdDyf/87aUpkIc/GSOm93psSnPFrwcA+km69Psy6Qg93JI\r\nnMTcWxidqRRLn59KNFJ6gd4q5Wbuwb7Lgt4SdxJH1bSDmQMiU6+ZSvDNzlh4\r\nc1kWOCVefz0lptYLhy/+nB80ZaEbWROdVILULPz0O5pNU5TNDrAIbA/PFU7F\r\nGlNZuBM4q0ZN5CCPsR+ySfqJ7SCeUh5jiek=\r\n=cOKF\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"absaldanha","email":"absaldanha@protonmail.com"},"directories":{},"maintainers":[{"name":"absaldanha","email":"absaldanha@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stimulus-form_0.0.3_1678576689618_0.1484304165731405"},"_hasShrinkwrap":false}},"time":{"created":"2023-02-10T23:15:07.962Z","0.0.1":"2023-02-10T23:15:08.278Z","modified":"2023-03-11T23:18:09.883Z","0.0.2":"2023-02-12T03:14:16.592Z","0.0.3":"2023-03-11T23:18:09.775Z"},"maintainers":[{"name":"absaldanha","email":"absaldanha@protonmail.com"}],"description":"A simple form validation library for the `<form>` you already have.","repository":{"type":"git","url":"git+https://github.com/absaldanha/stimulus-form.git"},"author":{"name":"Alexandre Saldanha"},"license":"MIT","readme":"# StimulusForm\n\nA simple form validation library for the `<form>` you already have.\n\n## Getting Started\n\nTo install StimulusForm in your application, add the `stimulus_form` npm package to your JavaScript bundle.\n\n`@hotwired/stimulus` version 3.2 or greater is required because of its dependency on the [Outlet API](https://stimulus.hotwired.dev/reference/outlets).\n\n\n## Usage\n### Controller Registration\nImport and register `FormController` on your Stimulus application:\n\n```javascript\nimport { Application } from  '@hotwired/stimulus';\nimport { FormController } from  'stimulus_form';\n\nconst  app = Application.start();\n\napp.register('form', FormController);\n```\n\nThis library is composed of two Stimulus controllers designed to work with your forms:\n\n- `FormController`: is the \"coordinator\" controller, responsible for orchestrating the validation of all the form fields before an submission, preventing it if there are invalid fields. It's controller action is `submit`, usually added to the form submit button.\n- `FieldController`: the individual field controller, responsible for the field validations. It is automatically registered with the `field` identifier when `FormController` is registered. It's controller action is `validate`, usually added as response to events related to the input, such as the blur event.\n\nYou can write your HTML forms as usual, adding your new controllers like you normally do with any Stimulus controller:\n\n```html\n<form data-controller=\"form\" data-form-field-outlet=\".field\">\n  <div\n    class=\"field\"\n    data-controller=\"field\"\n    data-field-validations-value=\"required\"\n    data-field-error-class=\"field-error\"\n  >\n    <input name=\"field_name\" data-field-target=\"input\" data-action=\"blur->field#validate\">\n    <div data-field-target=\"error\"></div>\n  </div>\n\n  <button type=\"submit\" data-action=\"form#submit\">Send</button>\n</form>\n```\n### Fields\n\n`stimulus_form` uses Stimulus [Outlet API](https://stimulus.hotwired.dev/reference/outlets) to connect all your form fields (connected to an `FieldController`) to your form (connected to an `FormController`). Because of this, your `<form>` element must have an `data-form-field-outlet` attribute, and its value must be an valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) which you can to refer to your fields. In the example above, we used the `.field` CSS selector, indicating that our fields are identified by the `field` CSS class.\n\n### Validations\n\nField validations are specified with the `data-field-validations-value` attribute. It is a space-separated list of validator identifiers. There are many [built-in](#built-in-validators) validators shipped with the library, and you can [build and register your own validators](#custom-validators).\n\n### Targets\n\nThere are two `FieldController` targets, using the `data-field-target` attribute, that you must add to your HTML so your form validations work correctly:\n\n- `input` : specifies the field *input element*, which can be an `<input>`, `<select>` or `<textarea>` element. This is where the controller will fetch the value and validate it against your list of validations.\n- `error`: specifies the element where eventual errors will be displayed to your user in case the validation fails.\n\n### Actions\n\nThere are two controller actions that you can use on your form in order to trigger its validation behavior:\n\n- `FormController#submit`: its the action that will validate your entire form, preventing its submission in case any field validation fails.\n- `FieldController#validate`: its the action that will validate an individual field against the specified validations. It will automatically mark the field as invalid and show any validation error to your user.\n\n### Error Class\n\nWhen an field is marked as invalid, you can configure which CSS classes will be added to the field element. You can configure it with the `data-field-error-class` attribute, and it accepts an space-separated list of classes that will be toggled when a field is valid or invalid.\n\n## Validators\n\n### Built-in Validators\n\n`stimulus_form` ships with many validators ready to be used on your forms. Note that some validations require some options that must be specified with an semicolon separator e.g. `max-length:10`, `gt:5`, `eq:foo`\n\n| Identifier | Description | Example |\n|--|--|--|\n| `required` | Verify if the value is not `null`, `false`, `undefined` or an empty string | `required` |\n| `length` | Verify if the value character length is equal to the given number | `length:100` |\n| `max-length` | Verify if the value character length does not exceed the given limit | `max-length:50` |\n| `min-length` | Verify if the value character length is not under the given limit | `min-length:10` |\n| `gt` | Verify if the value is greater than the given number | `gt:17` |\n| `gteq` | Verify if the value is greater than or equal to the given number | `gteq:18` |\n| `lt` | Verify if the value is less than the specified number | `lt:40` |\n| `lteq` | Verify if the value is less than or equal to the given number | `lteq:50` |\n| `eq` | Verify if the value is equal to the given value | `eq:foo` |\n| `not-eq` | Verify if the value is different than the given value | `not-eq:bar` |\n| `format` | Verify if the value conforms to the given format (as an Regex). An special option `email` can be given to validate against an email format | `format:^bar.*foo$` or `format:email` |\n| `confirmation` | Verify if the value is equal to another field value with the given name | `confirmation:password` |\n\n### Custom Validators\n\nYou can build your own validators and register them to be used on your forms. Custom validators must implement the `ValidatorConstructor` and `Validator` interfaces and be added to the `validatorRegistry` with an unique identifier to be used on your `data-field-validations-value` attribute. For example:\n\n```typescript\nimport { validatorRegistry, ValidationContext } from 'stimulus_form';\nimport type { Validator, ValidatorConstructor } from 'stimulus_form';\n\n// The Validator interface specifies only one method `validate` that has the signature:\n// validate(field: FieldController, validationContext: ValidationContext)\nclass MinAgeValidator implements Validator {\n  age: string;\n\n  // The ValidatorConstructor interface specifies your custom validator interface,\n  // which must receive a string as argument, the options you specify after the semicolon\n  // e.g with a identifer `age:16`\n  constructor(options: string) {\n    this.age = Number(options);\n  }\n\n  // The validate method needs to add an error to the given field in order to\n  // mark it as invalid. The `FieldController` has an `errors` attribute where\n  // you can add a new error just like the example below.\n  validate(field: FieldControler, _validationContext: ValidationContext) {\n    const currentDateYear = new Date().getFullYear();\n    const fieldDateYear = new Date(field.value).getFullYear();\n\n    if ((currentDateYear - fieldDateYear) < this.age) {\n      field.errors.add('invalid');\n    }\n  }\n}\n\nvalidatorRegistry.add('age', MinAgeValidator);\n```\nNow you can use `age:18` on your fields just like any other built-in validator.\n\n## Error messages\n`stimulus_form` ships with error messages for all built-in validators, in the `en` and `pt-BR` locales (defaults to `en`). You can change or add new messages or change the locale with the `errorMessages` object:\n\n```typescript\nimport { errorMessages } from 'stimulus_form';\n\n// Adds a new message to the `foo` key to the current configured locale (en by default).\nerrorMessages.append({ foo: 'this is foo' });\n\n// Adds a new message to the `foo` key to the pt-BR locale.\nerrorMessages.append({ foo: 'isso é foo' }, 'pt-BR');\n\n// Adds a new message to the `foo` key to the fr locale.\nerrorMessages.append({ foo: \"c'est fou\" }, 'fr');\n\n// Sets the current locale to be used to fr\nerrorMessages.locale = 'fr';\n```\n\nFor reference on the keys used by the built-in validators, please refer to the used [locale files]().\n\n## Development\n","readmeFilename":"README.md"}