value change

This commit is contained in:
Kevin G Christiano 2020-05-08 14:08:47 -04:00
parent f1466763b7
commit 4f3f52195e

View File

@ -100,19 +100,19 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
private weak var proprietorTextDelegate: UITextViewDelegate?
/// The delegate and block for validation. Validates if the text that the user has entered.
public weak var observingTextFieldDelegate: ObservingTextFieldDelegate? {
public weak var observingTextViewdDelegate: ObservingTextFieldDelegate? {
didSet {
if observingTextFieldDelegate != nil && !observingForChange {
if observingTextViewdDelegate != nil && !observingForChange {
observingForChange = true
// NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextView.textDidChangeNotification, object: textView)
// NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextView.textDidEndEditingNotification, object: textView)
// NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextView.textDidChangeNotification, object: textView)
NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextView.textDidEndEditingNotification, object: textView)
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
} else if observingTextFieldDelegate == nil && observingForChange {
} else if observingTextViewdDelegate == nil && observingForChange {
observingForChange = false
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidEndEditingNotification, object: textView)
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: textView)
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
NotificationCenter.default.removeObserver(self, name: UITextView.textDidEndEditingNotification, object: textView)
NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: textView)
}
}
}
@ -127,12 +127,12 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
}
@objc public func setBothTextDelegates(to delegate: (UITextViewDelegate & ObservingTextFieldDelegate)?) {
observingTextFieldDelegate = delegate
observingTextViewdDelegate = delegate
uiTextViewDelegate = delegate
}
open func setupTextViewToolbar() {
let observingDelegate = observingTextFieldDelegate ?? self
let observingDelegate = observingTextViewdDelegate ?? self
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
action: #selector(observingDelegate.dismissFieldInput))
}
@ -154,9 +154,6 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
heightConstraint = textView.heightAnchor.constraint(equalToConstant: 0)
// let tap = UITapGestureRecognizer(target: self, action: #selector(startEditing))
// entryFieldContainer.addGestureRecognizer(tap)
accessibilityElements = [titleLabel, textView, feedbackLabel]
}
@ -178,38 +175,36 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
//
// /// Executes on UITextField.textDidBeginEditingNotification
// @objc func startEditing() {
// textView.becomeFirstResponder()
// }
//
// /// Executes on UITextField.textDidChangeNotification (each character entry)
// @objc func valueChanged() {
// guard validateEachCharacter else { return }
// isSelected = true
// validateTextField()
// }
//
// /// Validates the text of the entry field.
/// Validates the text of the entry field.
@objc public func validateTextField() {
text = textView.text
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
}
//
// /// Executes on UITextField.textDidEndEditingNotification
// @objc func endInputing() {
// resignFirstResponder()
// if isValid {
// showError = false
// entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
// }
// }
//
// @objc public func dismissFieldInput(_ sender: Any?) {
// resignFirstResponder()
// }
/// Executes on UITextField.textDidBeginEditingNotification
@objc func startEditing() {
isSelected = true
textView.becomeFirstResponder()
}
/// Executes on UITextField.textDidChangeNotification (each character entry)
@objc func valueChanged() {
guard validateEachCharacter else { return }
isSelected = true
validateTextField()
}
/// Executes on UITextField.textDidEndEditingNotification
@objc func endInputing() {
resignFirstResponder()
if isValid {
showError = false
entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
}
}
//--------------------------------------------------
// MARK: - UITextViewDelegate
//--------------------------------------------------