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