├── .eslintrc.json ├── .github └── workflows │ ├── linthtml.yml │ ├── lintjs.yml │ └── test.yml ├── .gitignore ├── .htmlhintrc ├── .npmignore ├── LICENSE ├── README.md ├── bin └── check ├── cypress.config.js ├── cypress ├── e2e │ ├── all_specs.cy.js │ ├── demo_playback │ │ └── demo.cy.js │ ├── events │ │ ├── blur │ │ │ ├── email.cy.js │ │ │ ├── json_validations.cy.js │ │ │ ├── length.cy.js │ │ │ ├── multiple_validations.cy.js │ │ │ ├── numericality.cy.js │ │ │ ├── presence.cy.js │ │ │ └── strong_password.cy.js │ │ └── input │ │ │ ├── email.cy.js │ │ │ ├── json_validations.cy.js │ │ │ ├── length.cy.js │ │ │ ├── multiple_validations.cy.js │ │ │ ├── numericality.cy.js │ │ │ ├── presence.cy.js │ │ │ └── strong_password.cy.js │ ├── i18n │ │ └── locales │ │ │ ├── en.cy.js │ │ │ ├── es.cy.js │ │ │ ├── fr.cy.js │ │ │ ├── invalid_locale.cy.js │ │ │ ├── pt_br.cy.js │ │ │ ├── zh_cn.cy.js │ │ │ └── zh_tw.cy.js │ └── styles │ │ ├── classes.cy.js │ │ └── css.cy.js ├── fixtures │ ├── example.json │ ├── fields.html │ └── i18n │ │ └── locales │ │ ├── en.html │ │ ├── es.html │ │ ├── fr.html │ │ ├── invalid_locale.html │ │ ├── pt_br.html │ │ ├── zh_cn.html │ │ └── zh_tw.html └── support │ ├── commands.js │ ├── e2e.js │ └── spec_helper.js ├── dist ├── stimulus-inline-input-validations.cjs ├── stimulus-inline-input-validations.cjs.map ├── stimulus-inline-input-validations.module.js └── stimulus-inline-input-validations.module.js.map ├── index.html ├── package.json ├── src ├── helpers │ └── regex.js ├── i18n │ ├── error_messages.js │ └── supported_locales.js ├── index.js ├── input_validator.js └── validations │ └── validate.js ├── styles └── tokyo_night_dark.css └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2020": true 5 | }, 6 | "extends": "standard", 7 | "overrides": [], 8 | "parserOptions": { 9 | "ecmaVersion": "latest", 10 | "sourceType": "module" 11 | }, 12 | "rules": { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/linthtml.yml: -------------------------------------------------------------------------------- 1 | name: LintHTML 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | linthtml: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v2 18 | 19 | - name: Setup Node.js 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: 16 23 | 24 | - name: Install dependencies 25 | run: yarn install 26 | 27 | - name: Run htmlhint 28 | run: yarn run htmlhint ./index.html 29 | -------------------------------------------------------------------------------- /.github/workflows/lintjs.yml: -------------------------------------------------------------------------------- 1 | name: LintJS 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | lintjs: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v2 18 | 19 | - name: Setup Node.js 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: 16 23 | 24 | - name: Install dependencies 25 | run: yarn install 26 | 27 | - name: Run ESLint 28 | run: yarn eslint src 29 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Cypress Tests 2 | 3 | on: push 4 | 5 | jobs: 6 | cypress-run: 7 | runs-on: ubuntu-22.04 8 | strategy: 9 | matrix: 10 | browser: [chrome, edge, electron, firefox] 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | 15 | - name: Set up Node.js 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: 16 19 | 20 | - name: Install dependencies 21 | run: yarn install 22 | 23 | - name: Cypress run 24 | run: yarn run cypress run --spec 'cypress/e2e/**/*.cy.js' --browser ${{ matrix.browser }} 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | yarn-error.log 3 | .DS_Store 4 | *.swp 5 | *.swo 6 | *~ 7 | /cypress/screenshots 8 | /cypress/downloads 9 | -------------------------------------------------------------------------------- /.htmlhintrc: -------------------------------------------------------------------------------- 1 | { 2 | "alt-require": true, 3 | "attr-lowercase": ["viewBox"], 4 | "attr-no-duplication": true, 5 | "attr-unsafe-chars": true, 6 | "attr-value-double-quotes": true, 7 | "attr-value-not-empty": false, 8 | "csslint": false, 9 | "doctype-first": false, 10 | "doctype-html5": true, 11 | "head-script-disabled": false, 12 | "href-abs-or-rel": false, 13 | "id-class-ad-disabled": true, 14 | "id-class-value": false, 15 | "id-unique": true, 16 | "inline-script-disabled": true, 17 | "inline-style-disabled": false, 18 | "jshint": false, 19 | "space-tab-mixed-disabled": "space", 20 | "spec-char-escape": false, 21 | "src-not-empty": true, 22 | "style-disabled": false, 23 | "tag-pair": true, 24 | "tag-self-close": false, 25 | "tagname-lowercase": true, 26 | "title-require": false 27 | } 28 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *.log 3 | .DS_Store 4 | .gitignore 5 | .yarn.lock 6 | .prettierrc.json 7 | /.git 8 | /.vscode 9 | /cypress/screenshots 10 | /cypress/downloads 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Mike Ray Arriaga 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [](https://www.npmjs.com/package/stimulus-inline-input-validations) [](https://github.com/mikerayux/stimulus-inline-input-validations/actions/workflows/ci.yml) 2 | # Stimulus Inline Input Validations 3 | 4 | [Try the Demo Here](https://mikerayux.github.io/stimulus-inline-input-validations/) 5 | 6 | [Check out the screencast](https://www.youtube.com/watch?v=XUPmmgzc2ZY) 7 | 8 | A Stimulus controller for validating form inputs and rendering their errors in a custom error element. Validations are 9 | performed on input and blur events. 10 | 11 | Looking for another awesome validations library to try? Check out [Formulus](https://github.com/marcoroth/formulus) 12 | 13 | ## Installation 14 | 15 | [StimulusJS](https://stimulusjs.org) installation is required. 16 | 17 | Add the package to your project: 18 | 19 | ```bash 20 | yarn add stimulus-inline-input-validations 21 | ``` 22 | 23 | Import and register `InputValidator` to your application 24 | 25 | ```javascript 26 | import {InputValidator} from "stimulus-inline-input-validations" 27 | application.register("input-validator", InputValidator) 28 | ``` 29 | 30 | 1. Add `data-controller="input-validator"` to your form or any parent element of `` elements you want to validate. 31 | 32 | 33 | ```html 34 |