Search code examples
ioseureka-forms

Eureka: Form validation not up-to-date


I have a Eureka form that uses validation rules and .cellUpdate() to reflect the validation status for each form field. Additionally, I want to display the validation status of the whole form (by colouring/enabling an "OK" button). For this purpose I use the valueHasBeenChanged callback function in my FormViewController. I cycle through all rows and test for row.isValid. However, it seems that isValid reflects the status before the value actually is changed.

How can I achieve the intended mechanism in a clean way (that is, not fiddling with global variables or the like)?


Solution

  • The callback is indeed called in RowOf<T>.didSet, but isValid gives the result of validationErrors.isEmpty. The validationErrors list in turn is updated after the row's internal _value has been set, causing the behaviour described in my question. As I understand, it is this way no matter what's the setting in the row's validationOptions.

    My remedy is to call row.validate() in my valueHasBeenChanged function to explicitly trigger the validation before I read the row's isValid status. The cost of an additional call of the row's validation rules is negligible for me.