Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error ordering issue #32

Closed
ronak-selldo opened this issue Jan 12, 2022 · 5 comments
Closed

Validation error ordering issue #32

ronak-selldo opened this issue Jan 12, 2022 · 5 comments

Comments

@ronak-selldo
Copy link

I want to show validation error messages at time of user tap on Registration button.
Now the issue is

func validationFailed(_ errors:[(Validatable ,ValidationError)])

here errors parameter returns the fields in unordered set.

can we show error messages in ordered set?

@gkaimakas
Copy link
Owner

hey @ronak-selldo

can you share a demo code so I better understand your use case?

@ronak-selldo
Copy link
Author

ronak-selldo commented Jan 12, 2022

@gkaimakas
Please check attached code.

`class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!

let validator = Validator()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    validator.registerField(nameTextField, rules: [RequiredRule(message: "name is required")]) // index 1
    validator.registerField(emailTextField, rules: [RequiredRule(message: "email is required")]) // index 2
}

@IBAction func registrationButtonTapped(_ sender: UIButton) {
    validator.validate(self)
}

}
extension ViewController: ValidationDelegate {
func validationSuccessful() { }

func validationFailed(_ errors:[(Validatable ,ValidationError)]) {
    for (_, error) in errors {
        print(error.message)
        // some times it prints (I want always error messages array in ordered set.)
        // 1. name is required // actual index 1
        // 2. email is required // actual index 2

        // and some times it prints (Unordered set)
        // 1. email is required // actual index 2
        // 2. name is required // actual index 1
    }
}

}

`

@gkaimakas
Copy link
Owner

@ronak-selldo not sure I recognise the syntax that you are using.

The Validator class in this library has only one function apply(_:) -> Bool. There are neither rules nor a ValidationDelegate.

Maybe you mistook this for something else? Please check your Podfile / Package.swift to make sure

@ronak-selldo
Copy link
Author

@gkaimakas
Sorry my bad. It is not the one which I used.

@gkaimakas
Copy link
Owner

no worries! honest mistake! take care!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants