Eureka
Eureka copied to clipboard
Enabling a button only if TextRows are not empty
How can I enable a button only if some TextRows and a PhoneRow are not empty?
This is how I build the TextRows and the PhoneRow:
`<<< TextRow("name") { row in
row.title = "Nome"
row.placeholder = "Nome"
row.add(rule: RuleRequired(msg: "Field required"))
row.validationOptions = .validatesOnChange
}`
`<<< TextRow("surname") { row in
row.title = "Cognome"
row.placeholder = "Cognome"
row.add(rule: RuleRequired(msg: "Field required"))
row.validationOptions = .validatesOnChange
}`
` <<< PhoneRow("phone") {
$0.title = "Numero di telefono"
$0.placeholder = "Numero"
$0.add(rule: RuleRequired(msg: "Field required"))
$0.validationOptions = .validatesOnChange
}`
And this is how I try to enable/disable the button depending on them
`<<< ButtonRow() {
$0.title = "Conferma"
$0.disabled = Condition.function(["name", "surname", "phone"], { form in
guard let isValidName = (form.rowBy(tag: "name") as? TextRow)?.isValid,
let isValidSurn = (form.rowBy(tag: "surname") as? TextRow)?.isValid,
let isValidPhone = (form.rowBy(tag: "phone") as? PhoneRow)?.isValid else { return true }
let isValidTotal = isValidName && isValidSurn && isValidPhone
return (isValidTotal)
})
}.onCellSelection({ (cell, row) in
if cell.row.isDisabled {
} else {
print("Button pressed")
}
})`
But this doesn't enable the ButtonRow when I write something in every TextRow How can I solve this problem?
This is a question for StackOverFlow.
Have you debugged your code? What is happening? Are the isValid
values wrong?
This is a question for StackOverFlow.
Have you debugged your code? What is happening? Are the
isValid
values wrong?
Actually, printing out the isValid always return
This is a question for StackOverFlow.
Have you debugged your code? What is happening? Are the
isValid
values wrong?
My bad, I'll move to StackOverFlow. Sorry for that, I'm quite a new user here on Github :) Also as you told me I debugged: the validations return incorrect data: the PhoneRow always returns false and the two TextRows return a different Boolean value every time their content changes.