Eureka Forms Swift 启用和禁用按钮
Eureka Forms Swift enable and disable button
我正在使用 Eureka Forms 在我的应用程序中创建注册功能。
我想弄清楚这个问题。
用户有一些字段需要提供给我们。在他删除所有信息并检查我们想要的所有按钮之前,我希望按钮提交为禁用或隐藏。当所需的行完成时,按钮应该可用/显示。
这是我用 eureka 制作的 Class
class RegisterViewController: FormViewController {
var xwra = 1
override func viewDidLoad() {
super.viewDidLoad()
LabelRow.defaultCellUpdate = { cell, row in
cell.contentView.backgroundColor = .red
cell.textLabel?.textColor = .white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 13)
cell.textLabel?.textAlignment = .right
}
TextRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
PhoneRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
PickerInlineRow<String>.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.backgroundColor = .red
}
}
PasswordRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
ButtonRow.defaultCellUpdate = { cell, row in
cell.textLabel?.numberOfLines = 0
}
form +++ Section("Τα Προσωπικά Στοιχεία σας")
<<< TextRow("name"){ row in
row.title = "Όνομα"
row.add(rule: RuleRequired())
row.validationOptions = .validatesOnChange
row.placeholder = "Enter text here"
}
.cellUpdate { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
<<< TextRow("surname"){ row in
row.title = "Επώνυμο"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("email"){ row in
row.title = "Email"
row.add(rule: RuleRequired())
row.add(rule: RuleEmail())
row.placeholder = "Enter text here"
}
<<< PhoneRow("phone"){
[=11=].title = "Τηλέφωνο"
[=11=].add(rule: RuleRequired())
[=11=].placeholder = "Enter text here"
}
<<< PhoneRow("fax"){
[=11=].title = "Φαξ"
[=11=].placeholder = "And numbers here"
}
+++ Section("Η Διεύθυνση σας")
<<< TextRow("company"){ row in
row.title = "Επωνυμία"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("job"){ row in
row.title = "Επάγγελμα"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("afm"){ row in
row.title = "Α.Φ.Μ. / Δ.Ο.Υ"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("address1"){ row in
row.title = "Διεύθυνση 1"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("address2"){ row in
row.title = "Διεύθυνση 2"
row.placeholder = "Enter text here"
}
<<< TextRow("town"){ row in
row.title = "Πόλη"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("tk"){ row in
row.title = "Τ.Κ."
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< PickerInlineRow<String>("countrytag") {
[=11=].title = "Χώρα"
[=11=].options = ["Ελλάδα", "Κύπρος"]
[=11=].add(rule: RuleRequired())
}.onChange { row in
if row.value == "Ελλάδα" {
self.xwra = 1
} else {
self.xwra = 0
}
}
<<< PickerInlineRow<String>("loctag") {
[=11=].title = "Πόλη"
[=11=].add(rule: RuleRequired())
}.onCellSelection({ (cell, row) in
if self.xwra == 1 {
print("its one")
row.options = ["Ελλάδα", "Κύπρος", "Κύπρος", "Κύπρος", "Κύπρος"]
row.updateCell()
} else {
print("its not one")
row.options = ["Ελλάδα"]
row.updateCell()
}
})
+++ Section(header: "O Κωδικος σας", footer: "Θα πρέπει να είναι ίδιος και στα δύο πεδία.")
<<< PasswordRow("password") {
[=11=].title = "Password"
}
<<< PasswordRow() {
[=11=].title = "Confirm Password"
[=11=].add(rule: RuleEqualsToRow(form: form, tag: "password"))
}
.cellUpdate { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
+++ Section("Λήψη Ενημερωτικών Δελτίων")
<<< SwitchRow("SwitchRow") { row in
row.title = "The title"
}
+++ SelectableSection<ImageCheckRow<String>>("", selectionType: .singleSelection(enableDeselection: true))
<<< ImageCheckRow<String>(){ lrow in
lrow.title = "Έχω διαβάσει και αποδέχομαι τους όρους χρήσης - δήλωσης απορρήτου"
lrow.selectableValue = ""
lrow.value = nil
}.cellSetup { cell, _ in
cell.trueImage = UIImage(named: "selectedRectangle")!
cell.falseImage = UIImage(named: "unselectedRectangle")!
}
<<< ButtonRow("terms") {
[=11=].title = "Όροι Χρήσης - Δήλωση Απορρήτου"
[=11=].presentationMode = .segueName(segueName: "oroi", onDismiss: nil)
}
<<< ButtonRow("register") {
[=11=].title = "Εγγραφή"
[=11=].cell.backgroundColor = .red
[=11=].cell.tintColor = .white
}
.onCellSelection { cell, row in
//send data to server function
}
}
}
有人可以告诉我如何让它工作吗?
非常感谢!
更新 1.
最后一个按钮
<<< ButtonRow("register") {
[=12=].title = "Εγγραφή"
[=12=].cell.backgroundColor = .red
[=12=].cell.tintColor = .white
}
.onCellSelection { cell, row in
row.section?.form?.validate()
}
在选择单元格时,检查所有需要的数据,如果不正确,文本将变为红色。
所以问题又是一样的。如果验证为真,我如何 运行 发送到服务器功能?
我遇到了同样的问题,下面的代码获取错误计数,如果它是 0 则表单正常,如果有任何错误则继续执行下一个函数,它什么都不做。
<<< ButtonRow() { (row: ButtonRow) -> Void in
row.title = "LOGIN"
}
.onCellSelection { [weak self] (cell, row) in
print("validating errors: \(row.section?.form?.validate().count)")
if row.section?.form?.validate().count == 0{
self?.loginAction(row)
}
}
此示例在末尾添加一个按钮,该按钮将被禁用,直到所有行都通过验证:
<<< ButtonRow("signin") {
[=10=].title = "Sign In"
[=10=].disabled = Condition.function(
form.allRows.flatMap { [=10=].tag }, // All row tags
{ ![=10=].validate().isEmpty }) // Form has no validation errors
}
我正在使用 Eureka Forms 在我的应用程序中创建注册功能。
我想弄清楚这个问题。
用户有一些字段需要提供给我们。在他删除所有信息并检查我们想要的所有按钮之前,我希望按钮提交为禁用或隐藏。当所需的行完成时,按钮应该可用/显示。
这是我用 eureka 制作的 Class
class RegisterViewController: FormViewController {
var xwra = 1
override func viewDidLoad() {
super.viewDidLoad()
LabelRow.defaultCellUpdate = { cell, row in
cell.contentView.backgroundColor = .red
cell.textLabel?.textColor = .white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 13)
cell.textLabel?.textAlignment = .right
}
TextRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
PhoneRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
PickerInlineRow<String>.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.backgroundColor = .red
}
}
PasswordRow.defaultCellUpdate = { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
ButtonRow.defaultCellUpdate = { cell, row in
cell.textLabel?.numberOfLines = 0
}
form +++ Section("Τα Προσωπικά Στοιχεία σας")
<<< TextRow("name"){ row in
row.title = "Όνομα"
row.add(rule: RuleRequired())
row.validationOptions = .validatesOnChange
row.placeholder = "Enter text here"
}
.cellUpdate { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
<<< TextRow("surname"){ row in
row.title = "Επώνυμο"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("email"){ row in
row.title = "Email"
row.add(rule: RuleRequired())
row.add(rule: RuleEmail())
row.placeholder = "Enter text here"
}
<<< PhoneRow("phone"){
[=11=].title = "Τηλέφωνο"
[=11=].add(rule: RuleRequired())
[=11=].placeholder = "Enter text here"
}
<<< PhoneRow("fax"){
[=11=].title = "Φαξ"
[=11=].placeholder = "And numbers here"
}
+++ Section("Η Διεύθυνση σας")
<<< TextRow("company"){ row in
row.title = "Επωνυμία"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("job"){ row in
row.title = "Επάγγελμα"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("afm"){ row in
row.title = "Α.Φ.Μ. / Δ.Ο.Υ"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("address1"){ row in
row.title = "Διεύθυνση 1"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("address2"){ row in
row.title = "Διεύθυνση 2"
row.placeholder = "Enter text here"
}
<<< TextRow("town"){ row in
row.title = "Πόλη"
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< TextRow("tk"){ row in
row.title = "Τ.Κ."
row.add(rule: RuleRequired())
row.placeholder = "Enter text here"
}
<<< PickerInlineRow<String>("countrytag") {
[=11=].title = "Χώρα"
[=11=].options = ["Ελλάδα", "Κύπρος"]
[=11=].add(rule: RuleRequired())
}.onChange { row in
if row.value == "Ελλάδα" {
self.xwra = 1
} else {
self.xwra = 0
}
}
<<< PickerInlineRow<String>("loctag") {
[=11=].title = "Πόλη"
[=11=].add(rule: RuleRequired())
}.onCellSelection({ (cell, row) in
if self.xwra == 1 {
print("its one")
row.options = ["Ελλάδα", "Κύπρος", "Κύπρος", "Κύπρος", "Κύπρος"]
row.updateCell()
} else {
print("its not one")
row.options = ["Ελλάδα"]
row.updateCell()
}
})
+++ Section(header: "O Κωδικος σας", footer: "Θα πρέπει να είναι ίδιος και στα δύο πεδία.")
<<< PasswordRow("password") {
[=11=].title = "Password"
}
<<< PasswordRow() {
[=11=].title = "Confirm Password"
[=11=].add(rule: RuleEqualsToRow(form: form, tag: "password"))
}
.cellUpdate { cell, row in
if !row.isValid {
cell.titleLabel?.textColor = .red
}
}
+++ Section("Λήψη Ενημερωτικών Δελτίων")
<<< SwitchRow("SwitchRow") { row in
row.title = "The title"
}
+++ SelectableSection<ImageCheckRow<String>>("", selectionType: .singleSelection(enableDeselection: true))
<<< ImageCheckRow<String>(){ lrow in
lrow.title = "Έχω διαβάσει και αποδέχομαι τους όρους χρήσης - δήλωσης απορρήτου"
lrow.selectableValue = ""
lrow.value = nil
}.cellSetup { cell, _ in
cell.trueImage = UIImage(named: "selectedRectangle")!
cell.falseImage = UIImage(named: "unselectedRectangle")!
}
<<< ButtonRow("terms") {
[=11=].title = "Όροι Χρήσης - Δήλωση Απορρήτου"
[=11=].presentationMode = .segueName(segueName: "oroi", onDismiss: nil)
}
<<< ButtonRow("register") {
[=11=].title = "Εγγραφή"
[=11=].cell.backgroundColor = .red
[=11=].cell.tintColor = .white
}
.onCellSelection { cell, row in
//send data to server function
}
}
}
有人可以告诉我如何让它工作吗? 非常感谢!
更新 1.
最后一个按钮
<<< ButtonRow("register") {
[=12=].title = "Εγγραφή"
[=12=].cell.backgroundColor = .red
[=12=].cell.tintColor = .white
}
.onCellSelection { cell, row in
row.section?.form?.validate()
}
在选择单元格时,检查所有需要的数据,如果不正确,文本将变为红色。 所以问题又是一样的。如果验证为真,我如何 运行 发送到服务器功能?
我遇到了同样的问题,下面的代码获取错误计数,如果它是 0 则表单正常,如果有任何错误则继续执行下一个函数,它什么都不做。
<<< ButtonRow() { (row: ButtonRow) -> Void in
row.title = "LOGIN"
}
.onCellSelection { [weak self] (cell, row) in
print("validating errors: \(row.section?.form?.validate().count)")
if row.section?.form?.validate().count == 0{
self?.loginAction(row)
}
}
此示例在末尾添加一个按钮,该按钮将被禁用,直到所有行都通过验证:
<<< ButtonRow("signin") {
[=10=].title = "Sign In"
[=10=].disabled = Condition.function(
form.allRows.flatMap { [=10=].tag }, // All row tags
{ ![=10=].validate().isEmpty }) // Form has no validation errors
}