Eureka: Is it possible to scroll to first invalid form field after validating the whole Form?

Created on 19 Feb 2018  路  1Comment  路  Source: xmartlabs/Eureka

Is it possible to scroll to the first form field that is invalid after calling validate on the form?
I just get an array of validationErrors but not a list of rows or cells I could work with?

Most helpful comment

I found a solution by myself but I am not sure if this is the best approach.
Basically I am validating the whole form so the field get marked as invalid
and than I validate each field again to get the first field that is invalid.

private func validateForm(form: Form) -> Bool {
    form.validate()
    for row in form.allRows.filter({ !$0.isHidden}) {
        guard row.validate().isEmpty else {
            row.baseCell.becomeFirstResponder()
        row.select(animated: true, scrollPosition: .top)
        return false
        }
    }
    return true
}

>All comments

I found a solution by myself but I am not sure if this is the best approach.
Basically I am validating the whole form so the field get marked as invalid
and than I validate each field again to get the first field that is invalid.

private func validateForm(form: Form) -> Bool {
    form.validate()
    for row in form.allRows.filter({ !$0.isHidden}) {
        guard row.validate().isEmpty else {
            row.baseCell.becomeFirstResponder()
        row.select(animated: true, scrollPosition: .top)
        return false
        }
    }
    return true
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

annjawn picture annjawn  路  3Comments

fpena picture fpena  路  3Comments

Tomas1405 picture Tomas1405  路  3Comments

s1rc picture s1rc  路  3Comments

Tomas1405 picture Tomas1405  路  3Comments