Merge branch 'develop' into feature/radio_swatches

This commit is contained in:
Lekshmi S 2020-04-14 14:26:40 +05:30
commit 465fb26e8a
6 changed files with 21 additions and 23 deletions

View File

@ -276,7 +276,7 @@ import UIKit
let fallbackImageName = customFallbackImage ?? MVMCoreUIUtility.localizedImageName("fallback")
if let format = format, format.lowercased().contains("gif") {
// Gifs aren't supported by default and need special handling
MVMCoreCache.shared()?.getGif(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, allowServerQueryParameters: allowServerParameters, completionHandler: finishedLoadingBlock)
MVMCoreCache.shared()?.getGif(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, allowServerQueryParameters: allowServerParameters, localBundle: localBundle, completionHandler: finishedLoadingBlock)
} else {
MVMCoreCache.shared()?.getImage(imageName, useWidth: width != nil, widthForS7: width?.intValue ?? 0, useHeight: height != nil, heightForS7: height?.intValue ?? 0, format: format, localFallbackImageName: fallbackImageName, allowServerQueryParameters: allowServerParameters, localBundle: localBundle, completionHandler: finishedLoadingBlock)
}

View File

@ -89,7 +89,7 @@ import MVMCore
// Validate each rule.
var valid = true
for rule in group.rules {
valid = valid && validateRule(rule)
valid = valid && rule.validate(fields)
}
// Notify the group watchers of validity.
@ -98,19 +98,6 @@ import MVMCore
watcher.setValidity(valid, group: group)
}
}
return valid
}
/// Validates a given rule. Returns if valid.
public func validateRule(_ rule: RulesProtocol) -> Bool {
var valid = true
for formKey in rule.fields {
guard let formField = fields[formKey] else { continue }
let fieldValidity = rule.isValid(formField)
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: rule)
valid = valid && fieldValidity
}
return valid
}
}

View File

@ -35,7 +35,7 @@ public class RuleAnyRequiredModel: RulesProtocol {
return false
}
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
for formKey in fields {
guard let formField = fieldMolecules[formKey] else { continue }

View File

@ -26,16 +26,13 @@ public class RuleAnyValueChangedModel: RulesProtocol {
return formField.baseValue != formField.formFieldValue()
}
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
for formKey in fields {
guard let formField = fieldMolecules[formKey] else { continue }
if isValid(formField) {
return true
}
}
}
return false
}
}

View File

@ -26,8 +26,7 @@ public class RuleEqualsModel: RulesProtocol {
return false
}
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
var valid = true
var compareValue: AnyHashable?

View File

@ -22,6 +22,9 @@ public protocol RulesProtocol: ModelProtocol {
// Returns if a given field is valid according to the rule
func isValid(_ formField: FormFieldProtocol) -> Bool
// Validates the rule and returns the result.
func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool
}
public extension RulesProtocol {
@ -37,4 +40,16 @@ public extension RulesProtocol {
static var categoryName: String {
return "\(RulesProtocol.self)"
}
// Individual rule can override the function to validate based on the rule type.
func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
var valid = true
for formKey in fields {
guard let formField = fieldMolecules[formKey] else { continue }
let fieldValidity = isValid(formField)
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: self)
valid = valid && fieldValidity
}
return valid
}
}