diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 33224f8a..52580f46 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -298,14 +298,11 @@ self.uiTextFieldDelegate = delegate; } -- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id)delegate { +- (void)setWithMap:(nullable NSDictionary *)map { if (map.count == 0) { return; } - [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate]; - [self setBothTextFieldDelegates:delegate]; - NSString *string = [map string:KeyLabel]; if (string.length > 0) { self.formText = string; @@ -351,6 +348,12 @@ } } +- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id)delegate { + [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate]; + [self setBothTextFieldDelegates:delegate]; + [self setWithMap:map]; +} + - (void)setValidationBlock:(BOOL (^)(NSString * _Nullable))validationBlock { _validationBlock = validationBlock; [self valueChanged]; @@ -560,7 +563,11 @@ if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; - [self setWithMap:json bothDelegates:formValidator]; + + [self setWithMap:json]; + self.mfTextFieldDelegate = formValidator; + self.uiTextFieldDelegate = ((MVMCoreUIDelegateObject *)delegateObject).uiTextFieldDelegate; + [MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate]; } } diff --git a/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift b/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift index 2532910d..b2b18ebe 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator+TextFields.swift @@ -8,63 +8,6 @@ import Foundation -@objc extension FormValidator: UITextFieldDelegate { - public func textFieldDidEndEditing(_ textField: UITextField) { - enableByValidation() - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidEndEditing?(textField) - } - } - - public func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldReturn?(textField) ?? true - } - return true - } - - public func textFieldDidBeginEditing(_ textField: UITextField) { - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidBeginEditing?(textField) - } - } - - public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldBeginEditing?(textField) ?? true - } - return true - } - - public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldEndEditing?(textField) ?? true - } - return true - } - - public func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) { - if let delegate = delegate as? UITextFieldDelegate { - delegate.textFieldDidEndEditing?(textField, reason: reason) - } - } - - public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true - } - return true - } - - public func textFieldShouldClear(_ textField: UITextField) -> Bool { - if let delegate = delegate as? UITextFieldDelegate { - return delegate.textFieldShouldClear?(textField) ?? true - } - return true - } -} - @objc extension FormValidator: MFTextFieldDelegate { public func dismissFieldInput(_ sender: Any?) { if let delegate = delegate as? MFTextFieldDelegate { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift index eaf892fb..92744a8c 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIDelegateObject.swift @@ -11,10 +11,12 @@ import UIKit open class MVMCoreUIDelegateObject: DelegateObject { public weak var formValidationProtocol: FormValidationProtocol? public weak var buttonDelegate: ButtonDelegateProtocol? - + public weak var uiTextFieldDelegate: UITextFieldDelegate? + open override func setAll(withDelegate delegate: Any) { super.setAll(withDelegate: delegate) formValidationProtocol = delegate as? FormValidationProtocol buttonDelegate = delegate as? ButtonDelegateProtocol + uiTextFieldDelegate = delegate as? UITextFieldDelegate } }