We plan to add native validations to Eureka.
We also want to separate the logical validation part and the UI part of showing errors the most we can.
Display errors or not: Specify if the result of the validation should be shown or not. We might want to validate rows silently.
How validations are shown: To be able to define how a validation result will be shown for each row or type of cell.
Form validations: FormViewController should be able to show if a form is valid or invalid knowing which rows failed validation.
Define rules of validation that can be reused. This rules should have a name and an associated execution block taking the row to be validated and returning a boolean result.
required variable that determines if an error in this row invalidates the form.showValidation variable that determines if the error should be shown or notonValidation similar to 'cellUpdate'.Note: List sections will have to support the same behaviour as the rows
Great, I have been waiting for it for a long time.
I was trying to integrate Eureka with other validation libraries, but I really think that validation should be native.
I love your features list, just some point that I found useful from my experience:
Do you have any release date idea for this feature?
No, there is no release date. We want to think a bit more about it and then find some time to implement it.
This is the missing piece of the puzzle for Eureka. Feature list looks good.
I have made a workaround till Eureka comes with proper validation as XLForm.
func validateForm(formValues:[String:Any?], sender:UIViewController) -> Bool {
for (key,value) in formValues{
if key.containsString("*") && value == nil {
formValidationError(key, sender: sender)
return false
}
}
return true
}
You just need to add * with title while initialising your form like
<<< PickerInlineRow<String>("Method") { row in
row.title = "Method*"
row.options = followUpMethod
}
And you can validate the whole form before submitting like
if validateForm(form.values(), sender: self) {
}
Cheers for this workaround and open for any other suggestions.
Thanks
This feature has been implemented in Eureka 2.0 beta 1. Take a look at the repository readme for more information.
Any feedback is welcomed.
Thanks for this. When I eventually convert the project to Swift 3 I will definitely make use of this. Something that's not really made clear in the README is whether or not a row that doesn't pass validation has some sort of a "error" displayed on the default rows (TextRow, DateRow etc.). Is this the case?
In order to change how a row looks like depending on validations result you should use row.isValid from cellUpdate callback.
By default Eureka validations doesn't alter the UI. Take a look at the example project to know how to do so.
I am using the new validations feature in my project and it's great! Would love to see support for validating list sections (e.g. at least one row must be selected). Maybe the validation related parts of BaseRow could be split out into a Validatable protocol to which Sections could conform?
Most helpful comment
I am using the new validations feature in my project and it's great! Would love to see support for validating list sections (e.g. at least one row must be selected). Maybe the validation related parts of BaseRow could be split out into a Validatable protocol to which Sections could conform?