Giter Club home page Giter Club logo

Comments (7)

lmcd avatar lmcd commented on September 7, 2024 3

Here's a temporary hack for if your fields are laid out from top to bottom:

let errorArray = errors.values.sort({
    $0.textField.frame.origin.y < $1.textField.frame.origin.y
})

from swiftvalidator.

w-k-s avatar w-k-s commented on September 7, 2024 1

I tried @ed-mejia 's suggestion but got the following error (Swift Validator Tag v4.0.0):

Value of type 'ObjectIdentifier' has no member 'frame'

In case anyone else has the same issue, this worked for me:

extension Validator {
    typealias ValidatorErrorsTuple = (validatable: Validatable,error: ValidationError)
    var errorsOrdered: [(Validatable,ValidationError)] {
        get {

            let errorArray = errors.map {

                (tuple: (identifier: ObjectIdentifier, error: ValidationError)) -> (Validatable, ValidationError) in

                return (tuple.error.field,tuple.error)

            }.sort { (first: ValidatorErrorsTuple, second: ValidatorErrorsTuple) -> Bool in

                if let firstView = first.validatable as? UIView,
                    secondView = second.validatable as? UIView{

                    return firstView.frame.origin.y < secondView.frame.origin.y
                }
                return false
            }

            return  errorArray
        }
    }
}

from swiftvalidator.

jpotts18 avatar jpotts18 commented on September 7, 2024

Currently this is not supported.

from swiftvalidator.

ed-mejia avatar ed-mejia commented on September 7, 2024

Hi, I had the same issue, following @lmcd recommendation I implemented this extension:

//MARK: Validator
extension Validator {
    /*  this extension/hack was created because the validation library does not provide the returned
        ValidationErrors ordered in the same way we added them or in the way they are being displayed on screen */
    /// return the errors ordered by the frame (y coordinate)
    typealias ValidatorErrorsTuple = (UITextField,ValidationError)
    var errorsOrdered: [ValidatorErrorsTuple] {
        get {
            let errorArray = errors.sort({
                $0.0.frame.origin.y < $1.0.frame.origin.y
            })
            return  errorArray
        }
    }
}

This way we have the _same tuple value_ returned originally by _errors_ property but ordered.

from swiftvalidator.

mcka avatar mcka commented on September 7, 2024

updated by adding superview

let errorArray = validator.errors.values.sort({
    $0.textField.superview?.superview!.frame.origin.y < $1.textField.superview?.superview!.frame.origin.y
})

from swiftvalidator.

okhanokbay avatar okhanokbay commented on September 7, 2024

I added this code to failed delegate method.

let errorArray = errors.sorted {
    ($0.0 as! UITextField).frame.origin.y < ($1.0 as! UITextField).frame.origin.y
  }

from swiftvalidator.

jpotts18 avatar jpotts18 commented on September 7, 2024

Declaring Backlog Bankruptcy!

I'm not going to lie this project took off and I'm pretty overwhelmed by it. I no longer actively code in Swift and I need help from more contributors in order to keep this project relevant. I'd like to find someone to transition as lead maintainer or help this codebase find a happy home with a company.

The codebase for this project is relatively small and focused project for who is looking to contribute. It does one thing, and does it pretty well. It has pretty high test coverage and good adoption. I think my ideal maintainer / contributor would work for a company that actively uses SwiftValidator in their production application.

If you're interested in helping out please comment on #204

from swiftvalidator.

Related Issues (20)

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.