Giter Site home page Giter Site logo

validation's People

Contributors

jamieomatthews avatar patricksuo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

validation's Issues

Outdated readme.

This code:

func (ur UserRegistration) Validation(errors binding.Errors, req *http.Request) binding.Errors {
    v := validation.NewValidation(errors, ur)

    v.Validate(&ur.Name).Key("fullname").MaxLength(20)
    v.Validate(&ur.Email).Default("Custom Email Validation Message").Classify("email-class").Email()
    v.Validate(&ur.PlainPassword).TrimSpace().MinLength(6)

    return *v.Errors.(*binding.Errors)
}

produce some errors:

cannot use errors (type binding.Errors) as type validation.Errors in function argument:
    binding.Errors does not implement validation.Errors (Add method has pointer receiver)
v.Validate(&ur.Email).Default undefined (type *validation.Set has no field or method Default)

get incorrect key when two fields have the same value

Validation.getKeyForField compare v.Obj 's filed value to passedField value to figure out the key. If two fields have the same value, it picks the first matched field and may return an incorrect key.

package main

import (
        "fmt"

        //"github.com/jamieomatthews/validation"
        "github.com/sillyousu/validation"
)

type User struct {
        Name string `form:"username"`
        NickName string `form:"nickname"`
}

func main() {
        user := &User{Name: "su21", NickName: "su21"}
       //I want to get an empty `validation.Errors{}` 
        errors := validation.NewErrors()
        v := validation.New(errors, user)
        v.Validate(user.NickName).MinLength(5)

        fmt.Println("============")
        for i := 0; i < v.Errors.Len(); i++ {
                err := v.Errors.At(i)
                fmt.Printf("\nerr: %#v\n", err)
        }
}

Result

TypeObj: *main.User
Field: su21  passedField: su21
Is Equal!!
Got Key?  username
Min Length: ' su21 '
============

err: &validation.error{fields:[]string{"username"}, classification:"", message:"Minimum Length is 5"}

I think v.Validate("FieldName") is more reasonable.

binding.Errors does not implement validation.Errors

I can't seem to use this with the given example and binding:

cannot use errors (type binding.Errors) as type validation.Errors in function argument:
    binding.Errors does not implement validation.Errors (missing Add method)
impossible type assertion:
    *binding.Errors does not implement validation.Errors (missing Add method)

It's the latest binding (from today)

Also what is the interface part in NewValidation?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.