So I've created a custom row which is just a row with a simply UITextView now I want to create a rule such that if the UITextView has under 100 characters the variable row.isValid will evaluate to false.
<<< TextViewRow("About Me") {
let cell = $0.baseCell as! TextViewCell
cell.textView.text = currentUser.aboutMe
$0.disabled = Condition.function([]) {
form in
print("in disabled")
let section = form.sectionBy(tag: "About Me")
let view = section!.header?.viewForSection(section!, type: .header) as! TitleHeaderView
if view.isLocked {
return true
} else {
return false
}
}
$0.cellUpdate({ (cell, row) in
if row.isDisabled {
cell.textView.isUserInteractionEnabled = false
cell.textView.textColor = UIColor.gray
} else {
cell.textView.isUserInteractionEnabled = true
cell.textView.textColor = UIColor.black
}
})
let ruleRequiredViaClosure = RuleClosure<String> { rowValue in
guard let rowValue = rowValue else {
return(ValidationError(msg : "Please write more!"))
}
let numberOfCharacters = rowValue.characters.count
return (numberOfCharacters < 250 ? ValidationError(msg: "Please write more!") : nil)
}
$0.add(rule: ruleRequiredViaClosure)
$0.validationOptions = .validatesOnDemand
}
With a normal TextRow this would compile and XCode won't throw any error, although since TextViewRow is a custom row I believe this is why it is throwing an error.
The error it gives me is that I need to use:
$0.add(ruleSet: ...)
but I can't find any documentation on it.
Also I'm not sure whether I am able to define my rule as I have since the rowValue in the closure probably isn't referencing anything. How would I fix this problem?