deadpixelsociety / passport

A Kotlin-based Android view validation library with a simple DSL.
MIT License
30 stars 1 forks source link

Error messages passed to multiple fields in batch mode #1

Closed jarro closed 7 years ago

jarro commented 7 years ago

I used the sample code and applied it to two fields. When I validate in batch mode, I end up with all three error messages on both fields.

Thanks for making this available, it is just what I was looking for.

deadpixelsociety commented 7 years ago

Hi jarro! Would you be able to provide an example reproduction? Thanks.

jarro commented 7 years ago

private val validator by lazy {
    passport {

        rules<String?>(view?.ti_username!!) {
            email()
            length(8, 32)
        }

        rules<String?>(view?.ti_middle!!) {
            numeric()
        }
    }
}

private fun validate(): Boolean{
    return validator.validate(view!!, ValidationMethod.IMMEDIATE)
}

With something like that, the numeric rule is applied to ti_username. Thought it was related to ValidationMethod.BATCH but happens with immediate as well. Seems like every rule is applied to every field.

deadpixelsociety commented 7 years ago

Thanks, I'll take a look.

deadpixelsociety commented 7 years ago

jarro, I've addressed this in the 2.0.1 release just now. What happened was that validators were being treated as singleton instances and being shared across views. I've changed this so that validators are now instanced from factory functions via Passport.validatorFactory().

I've updated the example activity to show this.

Thanks for the report!

jarro commented 7 years ago

Working great, thanks for the speedy fix.