value changed rules

This commit is contained in:
Suresh, Kamlesh 2020-03-06 17:26:42 -05:00
parent 1bbfb0390a
commit 521ad8711d
13 changed files with 88 additions and 56 deletions

View File

@ -18,8 +18,8 @@
011D958724042492000E3791 /* FormFieldProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D958624042492000E3791 /* FormFieldProtocol.swift */; };
011D95892404249B000E3791 /* FormProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95882404249B000E3791 /* FormProtocol.swift */; };
011D959B240451E3000E3791 /* RuleRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959A240451E3000E3791 /* RuleRequiredModel.swift */; };
011D959D2404536F000E3791 /* RuleAnyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959C2404536F000E3791 /* RuleAnyModel.swift */; };
011D959F240453A1000E3791 /* RuleValueChangeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959E240453A1000E3791 /* RuleValueChangeModel.swift */; };
011D959D2404536F000E3791 /* RuleAnyValueChangedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */; };
011D959F240453A1000E3791 /* RuleAllValueChangedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */; };
011D95A1240453D0000E3791 /* RuleEqualsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A0240453D0000E3791 /* RuleEqualsModel.swift */; };
011D95A3240453F8000E3791 /* RuleRegexModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A2240453F8000E3791 /* RuleRegexModel.swift */; };
011D95A5240455DC000E3791 /* FormGroupRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A4240455DC000E3791 /* FormGroupRule.swift */; };
@ -385,8 +385,8 @@
011D958624042492000E3791 /* FormFieldProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormFieldProtocol.swift; sourceTree = "<group>"; };
011D95882404249B000E3791 /* FormProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormProtocol.swift; sourceTree = "<group>"; };
011D959A240451E3000E3791 /* RuleRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleRequiredModel.swift; sourceTree = "<group>"; };
011D959C2404536F000E3791 /* RuleAnyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyModel.swift; sourceTree = "<group>"; };
011D959E240453A1000E3791 /* RuleValueChangeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleValueChangeModel.swift; sourceTree = "<group>"; };
011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyValueChangedModel.swift; sourceTree = "<group>"; };
011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAllValueChangedModel.swift; sourceTree = "<group>"; };
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleEqualsModel.swift; sourceTree = "<group>"; };
011D95A2240453F8000E3791 /* RuleRegexModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleRegexModel.swift; sourceTree = "<group>"; };
011D95A4240455DC000E3791 /* FormGroupRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormGroupRule.swift; sourceTree = "<group>"; };
@ -790,8 +790,8 @@
children = (
011D958424042432000E3791 /* RulesProtocol.swift */,
011D959A240451E3000E3791 /* RuleRequiredModel.swift */,
011D959C2404536F000E3791 /* RuleAnyModel.swift */,
011D959E240453A1000E3791 /* RuleValueChangeModel.swift */,
011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */,
011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */,
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */,
011D95A2240453F8000E3791 /* RuleRegexModel.swift */,
011D95A4240455DC000E3791 /* FormGroupRule.swift */,
@ -2010,7 +2010,7 @@
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */,
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,
011D959D2404536F000E3791 /* RuleAnyModel.swift in Sources */,
011D959D2404536F000E3791 /* RuleAnyValueChangedModel.swift in Sources */,
D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */,
C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */,
D29DF32421ED0DA2003B2FB9 /* TextButtonView.m in Sources */,
@ -2028,7 +2028,7 @@
D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */,
C695A69823C990C200BFB94E /* DoughnutChartView.swift in Sources */,
D29DF2CB21E7BFCC003B2FB9 /* MFSizeThreshold.m in Sources */,
011D959F240453A1000E3791 /* RuleValueChangeModel.swift in Sources */,
011D959F240453A1000E3791 /* RuleAllValueChangedModel.swift in Sources */,
011D95AD2406BB57000E3791 /* FormHolderProtocol.swift in Sources */,
946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */,
01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */,

View File

@ -29,6 +29,7 @@ import Foundation
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var text: String?
public var baseValue: JSONValue?
public var isValid: Bool? {
didSet {
@ -60,8 +61,12 @@ import Foundation
case groupName
}
public func formFieldValue() -> Any? {
return text
public func formFieldValue() -> JSONValue? {
if let text = text {
return JSONValue(stringLiteral: text)
} else {
return nil
}
}
//--------------------------------------------------

View File

@ -9,7 +9,6 @@
import Foundation
@objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -33,6 +32,7 @@ import Foundation
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var baseValue: JSONValue?
//--------------------------------------------------
// MARK: - Keys
@ -59,8 +59,8 @@ import Foundation
init(isChecked: Bool = false) {}
public func formFieldValue() -> Any? {
return isChecked
public func formFieldValue() -> JSONValue? {
return JSONValue(booleanLiteral: isChecked)
}
//--------------------------------------------------

View File

@ -83,8 +83,11 @@ import UIKit
return radioModel?.fieldKey
}
public func formFieldValue() -> String? {
return radioModel?.fieldValue
public func formFieldValue() -> JSONValue? {
if let fieldValue = radioModel?.fieldValue {
return JSONValue(stringLiteral: fieldValue)
}
return nil
}
// MARK: - MVMViewProtocol

View File

@ -7,22 +7,22 @@
//
import Foundation
import MVMCore
public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
public static var identifier: String = "radioButton"
public var backgroundColor: Color?
public var state: Bool? = false
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var fieldValue: String
public func formFieldValue() -> Any? {
return fieldValue
}
init(_ fieldKey: String, _ fieldValue: String) {
self.fieldKey = fieldKey
self.fieldValue = fieldValue
public var fieldValue: String?
public var baseValue: JSONValue?
public func formFieldValue() -> JSONValue? {
if let fieldValue = fieldValue {
return JSONValue(stringLiteral: fieldValue)
} else {
return nil
}
}
}

View File

@ -17,6 +17,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
public var alternateAction: ActionModelProtocol?
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var baseValue: JSONValue?
private enum CodingKeys: String, CodingKey {
case moleculeName
@ -29,8 +30,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
case groupName
}
public func formFieldValue() -> Any? {
return state
public func formFieldValue() -> JSONValue? {
return JSONValue(booleanLiteral: state)
}
public init(_ state: Bool) {

View File

@ -24,7 +24,8 @@ import MVMCore
}
public func insertMolecule(_ molecule: FormItemProtocol) {
if let molecule = molecule as? FormFieldProtocol {
if var molecule = molecule as? FormFieldProtocol {
molecule.baseValue = molecule.formFieldValue()
fieldMolecules.append(molecule)
}
if let molecule = molecule as? FormActionFieldProtocol {

View File

@ -11,5 +11,12 @@ import Foundation
public protocol FormFieldProtocol: FormItemProtocol {
var fieldKey: String? { get set }
func formFieldValue() -> Any?
var baseValue: JSONValue? { get set }
func formFieldValue() -> JSONValue?
}
extension FormFieldProtocol {
var baseValue: JSONValue? {
return nil
}
}

View File

@ -8,13 +8,13 @@
import Foundation
public class RuleValueChangeModel: RulesProtocol {
public class RuleAllValueChangedModel: RulesProtocol {
public static var identifier: String = "valueChanged"
public var ruleType: String = RuleAnyModel.identifier
public static var identifier: String = "allValueChanged"
public var ruleType: String = RuleAllValueChangedModel.identifier
public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool {
return false
return formField.baseValue != formField.formFieldValue()
}
}

View File

@ -1,20 +0,0 @@
//
// RuleAnyModel.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 2/24/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
public class RuleAnyModel: RulesProtocol {
public static var identifier: String = "any"
public var ruleType: String = RuleAnyModel.identifier
public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool {
return false
}
}

View File

@ -0,0 +1,32 @@
//
// RuleAnyModel.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 2/24/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
public class RuleAnyValueChangedModel: RulesProtocol {
public static var identifier: String = "anyValueChanged"
public var ruleType: String = RuleAnyValueChangedModel.identifier
public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool {
return formField.baseValue != formField.formFieldValue()
}
public func isValid(_ formValidator: FormValidator) -> Bool {
for formKey in fields {
guard let formField = formValidator.formField(for: formKey) else {
continue
}
if isValid(formField) {
return true
}
}
return false
}
}

View File

@ -10,10 +10,13 @@ import Foundation
import UIKit
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
private var selectedRadioButton: RadioButton?
private var fieldGroupName: String?
public var baseValue: JSONValue?
init(_ fieldKey: String?) {
self.fieldKey = fieldKey
@ -44,7 +47,7 @@ extension RadioButtonSelectionHelper {
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
}
public func formFieldValue() -> Any? {
public func formFieldValue() -> JSONValue? {
return selectedRadioButton?.formFieldValue()
}
}

View File

@ -121,8 +121,8 @@ import Foundation
// Helper models
try? ModelRegistry.register(RuleRequiredModel.self)
try? ModelRegistry.register(RuleAnyModel.self)
try? ModelRegistry.register(RuleValueChangeModel.self)
try? ModelRegistry.register(RuleAnyValueChangedModel.self)
try? ModelRegistry.register(RuleAllValueChangedModel.self)
try? ModelRegistry.register(RuleEqualsModel.self)
try? ModelRegistry.register(RuleRegexModel.self)
}