textfield enhancement
This commit is contained in:
parent
9d8953d229
commit
97cf39eaee
@ -45,7 +45,7 @@ import UIKit
|
||||
private var observingForChange: Bool = false
|
||||
|
||||
/// Validate on each entry in the textField. Default: false
|
||||
public var validateEachCharacter: Bool = false
|
||||
public var validateEachCharacter: Bool = true
|
||||
|
||||
/// Validate when user resigns editing. Default: true
|
||||
public var validateWhenDoneEditing: Bool = true
|
||||
@ -233,18 +233,17 @@ import UIKit
|
||||
}
|
||||
|
||||
@objc public func updateValidation(_ isValid: Bool) {
|
||||
let previousValidity = self.isValid
|
||||
self.isValid = isValid
|
||||
if isValid {
|
||||
showError = false
|
||||
observingTextFieldDelegate?.isValid?(textfield: self)
|
||||
|
||||
} else {
|
||||
if previousValidity && !isValid {
|
||||
showError = true
|
||||
observingTextFieldDelegate?.isInvalid?(textfield: self)
|
||||
} else if (!previousValidity && isValid) {
|
||||
showError = false
|
||||
observingTextFieldDelegate?.isValid?(textfield: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Executes on UITextField.textDidBeginEditingNotification
|
||||
@objc func startEditing() {
|
||||
|
||||
@ -254,9 +253,7 @@ import UIKit
|
||||
|
||||
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
||||
@objc func valueChanged() {
|
||||
|
||||
guard validateEachCharacter else { return }
|
||||
|
||||
validateTextField()
|
||||
}
|
||||
|
||||
|
||||
@ -100,7 +100,8 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
knobView.backgroundColor = isOn ? knobTintColor?.on : knobTintColor?.off
|
||||
self.constrainKnob()
|
||||
}
|
||||
|
||||
|
||||
(model as? ToggleModel)?.state = isOn
|
||||
FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
accessibilityValue = isOn ? MVMCoreUIUtility.hardcodedString(withKey: "AccOn") : MVMCoreUIUtility.hardcodedString(withKey: "AccOff")
|
||||
setNeedsLayout()
|
||||
@ -339,6 +340,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
||||
return
|
||||
}
|
||||
|
||||
self.model = model
|
||||
self.delegateObject = delegateObject
|
||||
let toggleModelJSON = toggleModel.toJSON()
|
||||
|
||||
|
||||
@ -468,7 +468,7 @@
|
||||
|
||||
// Since we have new data, build stuff for the screen and update the ui once the screen is done laying out.
|
||||
[self newDataBuildAndUpdate];
|
||||
|
||||
|
||||
self.needToupdateUIOnScreenSizeChanges = YES;
|
||||
|
||||
if (UIAccessibilityIsVoiceOverRunning()) {
|
||||
@ -479,12 +479,12 @@
|
||||
[self setupIntroAnimations];
|
||||
}
|
||||
|
||||
[self startValidation];
|
||||
}
|
||||
|
||||
- (void)newDataBuildAndUpdate {
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[self newDataBuildScreen];
|
||||
[self startValidation];
|
||||
self.needToUpdateUI = YES;
|
||||
[self.view setNeedsLayout];
|
||||
}];
|
||||
|
||||
@ -41,13 +41,9 @@ public extension RulesProtocol {
|
||||
guard let formField = formValidator.formField(for: formKey) else {
|
||||
continue
|
||||
}
|
||||
valid = valid && isValid(formField)
|
||||
if !valid {
|
||||
setValid(formField, valid)
|
||||
break
|
||||
} else {
|
||||
setValid(formField, valid)
|
||||
}
|
||||
let fieldValidity = isValid(formField)
|
||||
setValid(formField, fieldValidity)
|
||||
valid = valid && fieldValidity
|
||||
}
|
||||
return valid
|
||||
}
|
||||
|
||||
@ -560,8 +560,7 @@
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
|
||||
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
|
||||
[self setWithMap:json];
|
||||
self.mfTextFieldDelegate = delegateObject.uiTextFieldDelegate;
|
||||
[self setWithMap:json];
|
||||
self.uiTextFieldDelegate = delegateObject.uiTextFieldDelegate;
|
||||
[MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate];
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user