我正在使用 Eureka Forms 在我的应用程序中创建一个注册函数。
我想弄清楚这个问题。
用户有一些字段需要提供给我们。在他删除所有信息并检查我们想要的所有按钮之前,我希望按钮提交为禁用或隐藏。当所需的行完成时,按钮应该可用/显示。
这是我用eureka做的类
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"){
$0.title = "Τηλέφωνο"
$0.add(rule: RuleRequired())
$0.placeholder = "Enter text here"
}
<<< PhoneRow("fax"){
$0.title = "Φαξ"
$0.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") {
$0.title = "Χώρα"
$0.options = ["Ελλάδα", "Κύπρος"]
$0.add(rule: RuleRequired())
}.onChange { row in
if row.value == "Ελλάδα" {
self.xwra = 1
} else {
self.xwra = 0
}
}
<<< PickerInlineRow<String>("loctag") {
$0.title = "Πόλη"
$0.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") {
$0.title = "Password"
}
<<< PasswordRow() {
$0.title = "Confirm Password"
$0.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") {
$0.title = "Όροι Χρήσης - Δήλωση Απορρήτου"
$0.presentationMode = .segueName(segueName: "oroi", onDismiss: nil)
}
<<< ButtonRow("register") {
$0.title = "Εγγραφή"
$0.cell.backgroundColor = .red
$0.cell.tintColor = .white
}
.onCellSelection { cell, row in
//send data to server function
}
}
}
有人能告诉我如何让它发挥作用吗? 非常感谢!
更新 1.
最后一个按钮
<<< ButtonRow("register") {
$0.title = "Εγγραφή"
$0.cell.backgroundColor = .red
$0.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)
}
}
关于ios - Eureka Forms Swift 启用和禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42258773/
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
在启用Rack::Deflater来gzip我的响应主体时偶然发现了一些奇怪的东西。也许我遗漏了一些东西,但启用此功能后,响应被压缩,但是资源的ETag在每个请求上都会发生变化。这会强制应用程序每次都响应,而不是发送304。这在没有启用Rack::Deflater的情况下有效,我已经验证页面源没有改变。我正在运行一个使用thin作为Web服务器的Rails应用程序。Gemfile.lockhttps://gist.github.com/2510816有没有什么方法可以让我从Rack中间件获得更多的输出,这样我就可以看到发生了什么?提前致谢。 最佳答案
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
是否可以在PyYAML或Ruby的Psych引擎中禁用创建anchor和引用(并有效地显式列出冗余数据)?也许我在网上搜索时遗漏了一些东西,但在Psych中似乎没有太多可用的选项,而且我也无法确定PyYAML是否允许这样做.基本原理是我必须序列化一些数据并将其以可读的形式传递给一个不是真正的技术同事进行手动验证。有些数据是多余的,但我需要以最明确的方式列出它们以提高可读性(anchor和引用是提高效率的好概念,但不是人类可读性)。Ruby和Python是我选择的工具,但如果有其他一些相当简单的方法来“展开”YAML文档,它可能就可以了。 最佳答案
Devise是一个Ruby库,它为我提供了这个User类:classUser当写入:confirmable时,注册时会发送一封确认邮件。上周我不得不批量创建300个用户,所以我在恢复之前注释掉了:confirmable几分钟。现在我正在为用户批量创建创建一个UI,因此我需要即时添加/删除:confirmable。(我也可以直接修改Devise的源码,但我宁愿不去调和它)问题:如何即时添加/删除:confirmable? 最佳答案 WayneConrad的解决方案:user=User.newuser.skip_confirmation
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
基本上,我试图在用户单击链接(或按钮或某种类型的交互元素)时执行Rails方法。我试着把它放在View中:但这似乎没有用。它最终只是在用户甚至没有点击“添加”链接的情况下调用该函数。我也用link_to试过了,但也没用。我开始认为没有一种干净的方法可以做到这一点。无论如何,感谢您的帮助。附言。我在ApplicationController中定义了该方法,它是一个辅助方法。 最佳答案 View和Controller是相互独立的。为了使链接在Controller内执行函数调用,您需要对应用程序中的端点执行ajax调用。该路由应调用rub
我在ruby表单中有一个提交按钮f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id"我想在不使用任何javascript的情况下通过ruby禁用此按钮 最佳答案 添加disabled:true选项。f.submitbtn_text,class:"btnbtn-onemgt12mgb12",id:"btn_id",disabled:true 关于ruby-on-rails-如何在Rails中添加禁用的提交按钮,我们在St