Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ open class SCLAlertView: UIViewController {
fileprivate var inputs = [UITextField]()
fileprivate var input = [UITextView]()
internal var buttons = [SCLButton]()
fileprivate var onTextChanged: ((String) -> Void)?
fileprivate var selfReference: SCLAlertView?

public init(appearance: SCLAppearance) {
Expand Down Expand Up @@ -529,7 +530,7 @@ open class SCLAlertView: UIViewController {
}
}

open func addTextField(_ title:String?=nil)->UITextField {
open func addTextField(_ title: String? = nil, onTextChanged: ((String) -> Void)? = nil) -> UITextField {
// Update view height
appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextFieldHeight)
// Add text field
Expand All @@ -548,9 +549,21 @@ open class SCLAlertView: UIViewController {

contentView.addSubview(txt)
inputs.append(txt)

if let onTextChanged = onTextChanged {
self.onTextChanged = onTextChanged
txt.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
}

return txt
}

@objc open func textFieldDidChange(_ textField: UITextField) {
if let onTextChanged = onTextChanged, let text = textField.text {
onTextChanged(text)
}
}

open func addTextView()->UITextView {
// Update view height
appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextViewdHeight)
Expand Down