npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ent-validator-builder

v1.1.0

Published

Componente responsável pela configuração do FormValidator

Downloads

7

Readme

Validator Builder

Componente responsável pela configuração do FormValidator. Este componente é organizado através de duas Classes ValidatorBuilder e Validation.

Forma de Utilização

    Y.use('ent-portlet', 'ent-validator-builder', 'lib/custom-form-validator', function (Y) {
        const _portlet = new Y.Portlet('.search-benefits-portlet')
        
        const _config = new Y.ValidatorBuilder(_portlet.getFieldId(_query.form.id))
            .append(new Y.Validation(_query.fields.email.name).required().email().maxLength(75))
            .append(new Y.Validation(_query.fields.password.name).required().minLength(6).maxLength(18))
            .append(new Y.Validation(_query.fields.captcha.field.name).required().maxLength(4))
            .build()
    
        const validator = new Y.FormValidator(_config)
        
        validator.validate()
        if(validator.hasErrors()) {
            ...
        }
    })

Métodos: ValidatorBuilder

append(validation)

Incrementa a configuração das validações com base em uma instancia de Validation.

Exemplo:

    const _config = new Y.ValidatorBuilder(_query.form.id)
        .append(new Y.Validation(_query.fields.email.name).required().email().maxLength(75))
        .append(new Y.Validation(_query.fields.password.name).required().maxLength(75))
        .append(new Y.Validation(_query.fields.captcha.field.name).required().maxLength(4))
        .build()

    const validator = new Y.FormValidator(_config)

build()

Retorna a configuração da validação.

concat(rules, validation)

Adiciona a uma configuração de validação já pronta validações baseadas em uma instância de Validation.

Métodos: Validation

Método construtor

Pode receber como parâmetro o name do campo a ser validado.

Exemplo:

    new Y.Validation(_query.fields.email.name).required().email().maxLength(75)

required(boolean)

Determina se um campo é obrigatório.

Exemplo:

    const validation = new Y.Validation(_query.fields.email.name).required()

equalTo(fieldNameOrValue)

Determina se um campo contem o mesmo valor que o especificado.

Exemplo:

    new Y.ValidatorBuilder(_query.form.id)
    .append(new Y.Validation(_query.fields.password.name).required().maxLength(75))
    .append(new Y.Validation(_query.fields.confirmPassword.name).required().maxLength(75).equalTo(_query.fields.password.id))

max(value)

Determina um valor máximo para um campo numérico.

Exemplo:

    new Y.Validation(_query.fields.age.name).required().max(18)

min(value)

Determina um valor mínimo para um campo numérico.

Exemplo:

    new Y.Validation(_query.fields.age.name).required().min(18)

range(min, max)

Determina um intervalo de valores para um campo numéroco.

Exemplo:

    new Y.Validation(_query.fields.age.name).required().range(18, 60)

maxLength(value)

Determina uma quantidade máxima de caracteres para um determinado campo.

Exemplo:

    new Y.Validation(_query.fields.password.name).maxLength(75)

minLength(value)

Determina uma quantidade mínima de caracteres para um determinado campo.

Exemplo:

    new Y.Validation(_query.fields.password.name).minLength(6)

rangeLength(min, max)

Determina um intervalo de caracteres para um determinado campo.

Exemplo:

    new Y.Validation(_query.fields.password.name).rangeLength(6, 18)

number(boolean)

Determina se um vampo é numérico.

Exemplo:

    new Y.Validation(_query.fields.age.name).required().range(18, 60).number()

email(boolean)

Determina se um campo é do tipo email.

Exemplo:

    new Y.Validation(_query.fields.email.name).required().maxLength(75).email()

url(boolean)

Determina se um campo é do tipo url.

Exemplo:

    new Y.Validation(_query.fields.url.name).required().url()

acceptFiles(values)

Determina um array de arquivos permitidos para um campo do tipo upload.

Exemplo:

    new Y.Validation(_query.fields.image.name).required().acceptFiles(['jpg', 'gif', 'png'])

custom(validatorName, value)

Adiciona um validador customizado.

Exemplo:

    new Y.Validation(_query.fields.datePicker.name).required().custom('datepicker', true)
    new Y.Validation(_query.fields.birthDate.name).required().custom('birthDate')

from(fieldNames)

Adiciona as mesmas regras de validação a campos distintos.

Exemplo:

    new Y.Validation().required().maxLength(75).from([_query.fields.name.name, _query.fields.lastName.name, _query.fields.address.name])

build()

Constroi o objeto de configuração com base nas validalões adicionadas.