code optimization
This commit is contained in:
parent
d398a45054
commit
73342e40d1
@ -21,7 +21,7 @@
|
||||
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
|
||||
|
||||
@property (nonatomic) BOOL validationRequired;
|
||||
@property (nonatomic, strong) NSArray *requiredFieldsList;
|
||||
@property (nonatomic, strong) NSArray *requiredGroupsList;
|
||||
@property (nonatomic) BOOL smallButton;
|
||||
@property (assign, nonatomic) BOOL tinyButton;
|
||||
@property (nonatomic) CGFloat sizeForSizing;
|
||||
@ -670,7 +670,7 @@
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
|
||||
self.validationRequired = [json boolForKey:@"validationRequired"];
|
||||
self.requiredFieldsList = [json array:@"requiredFields"];
|
||||
self.requiredGroupsList = [json array:@"requiredGroups"];
|
||||
[FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
|
||||
|
||||
self.primaryButtonType = PrimaryButtonTypeCustom;
|
||||
@ -784,7 +784,7 @@
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)requiredGroups {
|
||||
return self.requiredFieldsList;
|
||||
return self.requiredGroupsList;
|
||||
}
|
||||
|
||||
- (void)enableField:(BOOL)enable {
|
||||
|
||||
@ -49,26 +49,22 @@ import MVMCore
|
||||
|
||||
public func enableByValidation() {
|
||||
for molecule in enableDisableMolecules {
|
||||
var requiredFields = molecule.requiredGroups?() ?? [dummyGroupName]
|
||||
if requiredFields.count == 0 {
|
||||
requiredFields = [dummyGroupName]
|
||||
var requiredGroups = molecule.requiredGroups?() ?? [dummyGroupName]
|
||||
if requiredGroups.count == 0 {
|
||||
requiredGroups = [dummyGroupName]
|
||||
}
|
||||
enableWithGroups(requiredFields, molecule)
|
||||
enableWithGroups(requiredGroups, molecule)
|
||||
}
|
||||
}
|
||||
|
||||
public func enableWithGroups(_ requiredGroupList: [String], _ enableDisableMolecule: FormValidationEnableDisableProtocol) {
|
||||
|
||||
var groupValidityMap: [String: Bool] = [:]
|
||||
for molecule in fieldMolecules {
|
||||
let valid = molecule.isValidField()
|
||||
let groupName = molecule.formFieldGroupName() ?? dummyGroupName
|
||||
groupValidityMap[groupName] = valid && (groupValidityMap[groupName] ?? true)
|
||||
}
|
||||
|
||||
let requiredGroupSet = Set(requiredGroupList)
|
||||
var valid = true
|
||||
for groupName in requiredGroupList {
|
||||
valid = valid && groupValidityMap[groupName] ?? false
|
||||
for molecule in fieldMolecules {
|
||||
let groupName = molecule.formFieldGroupName() ?? dummyGroupName
|
||||
if requiredGroupSet.contains(groupName) {
|
||||
valid = valid && molecule.isValidField()
|
||||
}
|
||||
}
|
||||
enableDisableMolecule.enableField?(valid)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user