You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
HerrHase 56ef1edcfe
init
10 months ago
example init 10 months ago
src init 10 months ago
.gitignore init 10 months ago
README.md init 10 months ago
bun.lockb init 10 months ago
bunfig.toml init 10 months ago
package.json init 10 months ago
webpack.config.js init 10 months ago

README.md

Tiny Components - Validator

Created with Riot.js

Validate Form or a Single Form-Field, Error Messages can be show just in time or after Submit entire Form.

For Validation this Component uses Validate.js

Install

npm install @tiny-components/validator --save

You can use it like this

<form class="form" onsubmit={ (event) => ( state.validator.submit(event) ) }>>
    <div class="field">
        <label>
            email
            <input type="email" name="email" onkeyup={ (event) => { state.validator.handle(event, 'email') }} />
        </label>
        <field-error errors={ state.validator.errors('email') } ></field-error>
    </div>
    <div class="field">
        <label>
            password
            <input type="password" name="email" onkeyup={ (event) => { state.validator.handle(event, 'password') }} />
        </label>
        <field-error errors={ state.validator.errors('password') } ></field-error>
    </div>
    <button type="submit">Send</button>
</form>

<script>
    import Validator from './validator.js'

    export default {

        state: {
            validator: { }
        },

        onBeforeMount() {
            // creating formValidator
            this.state.validator = new FormValidator(this.$('.form'), {
                'email': {
                    'presence': true,
                    'email': true
                },
                'password': {
                    'presence': true
                }
            })

            // adding on success
            this.state.validator.onSuccess((event, data) => {
                this.handleSuccess(event, data)
            })

            // adding on error
            this.state.validator.onError((event, errors, data) => {
                this.handleError(event, errors, data)
            })
        },

        /**
         *
         */
        handleSuccess(event, data)
        {
            event.preventDefault()
            this.update()
        },

        /**
         *
         */
        handleError(event, errors, data)
        {
            this.update()
        }

    }
</script>