Merge branch 'feature/formvalidator_improvements' into 'develop'

improvements

See merge request BPHV_MIPS/mvm_core_ui!63
This commit is contained in:
Suresh, Kamlesh 2019-05-07 10:25:14 -04:00
commit 682759bc9a
3 changed files with 15 additions and 63 deletions

View File

@ -298,14 +298,11 @@
self.uiTextFieldDelegate = delegate;
}
- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)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<UITextFieldDelegate, MFTextFieldDelegate>)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];
}
}

View File

@ -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 {

View File

@ -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
}
}