value changed rules
This commit is contained in:
parent
1bbfb0390a
commit
521ad8711d
@ -18,8 +18,8 @@
|
|||||||
011D958724042492000E3791 /* FormFieldProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D958624042492000E3791 /* FormFieldProtocol.swift */; };
|
011D958724042492000E3791 /* FormFieldProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D958624042492000E3791 /* FormFieldProtocol.swift */; };
|
||||||
011D95892404249B000E3791 /* FormProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95882404249B000E3791 /* FormProtocol.swift */; };
|
011D95892404249B000E3791 /* FormProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95882404249B000E3791 /* FormProtocol.swift */; };
|
||||||
011D959B240451E3000E3791 /* RuleRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959A240451E3000E3791 /* RuleRequiredModel.swift */; };
|
011D959B240451E3000E3791 /* RuleRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959A240451E3000E3791 /* RuleRequiredModel.swift */; };
|
||||||
011D959D2404536F000E3791 /* RuleAnyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959C2404536F000E3791 /* RuleAnyModel.swift */; };
|
011D959D2404536F000E3791 /* RuleAnyValueChangedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */; };
|
||||||
011D959F240453A1000E3791 /* RuleValueChangeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959E240453A1000E3791 /* RuleValueChangeModel.swift */; };
|
011D959F240453A1000E3791 /* RuleAllValueChangedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */; };
|
||||||
011D95A1240453D0000E3791 /* RuleEqualsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A0240453D0000E3791 /* RuleEqualsModel.swift */; };
|
011D95A1240453D0000E3791 /* RuleEqualsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A0240453D0000E3791 /* RuleEqualsModel.swift */; };
|
||||||
011D95A3240453F8000E3791 /* RuleRegexModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A2240453F8000E3791 /* RuleRegexModel.swift */; };
|
011D95A3240453F8000E3791 /* RuleRegexModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A2240453F8000E3791 /* RuleRegexModel.swift */; };
|
||||||
011D95A5240455DC000E3791 /* FormGroupRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011D95A4240455DC000E3791 /* FormGroupRule.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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyValueChangedModel.swift; sourceTree = "<group>"; };
|
||||||
011D959E240453A1000E3791 /* RuleValueChangeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleValueChangeModel.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>"; };
|
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>"; };
|
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>"; };
|
011D95A4240455DC000E3791 /* FormGroupRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormGroupRule.swift; sourceTree = "<group>"; };
|
||||||
@ -790,8 +790,8 @@
|
|||||||
children = (
|
children = (
|
||||||
011D958424042432000E3791 /* RulesProtocol.swift */,
|
011D958424042432000E3791 /* RulesProtocol.swift */,
|
||||||
011D959A240451E3000E3791 /* RuleRequiredModel.swift */,
|
011D959A240451E3000E3791 /* RuleRequiredModel.swift */,
|
||||||
011D959C2404536F000E3791 /* RuleAnyModel.swift */,
|
011D959C2404536F000E3791 /* RuleAnyValueChangedModel.swift */,
|
||||||
011D959E240453A1000E3791 /* RuleValueChangeModel.swift */,
|
011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */,
|
||||||
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */,
|
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */,
|
||||||
011D95A2240453F8000E3791 /* RuleRegexModel.swift */,
|
011D95A2240453F8000E3791 /* RuleRegexModel.swift */,
|
||||||
011D95A4240455DC000E3791 /* FormGroupRule.swift */,
|
011D95A4240455DC000E3791 /* FormGroupRule.swift */,
|
||||||
@ -2010,7 +2010,7 @@
|
|||||||
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
|
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
|
||||||
014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */,
|
014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */,
|
||||||
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,
|
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,
|
||||||
011D959D2404536F000E3791 /* RuleAnyModel.swift in Sources */,
|
011D959D2404536F000E3791 /* RuleAnyValueChangedModel.swift in Sources */,
|
||||||
D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */,
|
D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */,
|
||||||
C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */,
|
C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */,
|
||||||
D29DF32421ED0DA2003B2FB9 /* TextButtonView.m in Sources */,
|
D29DF32421ED0DA2003B2FB9 /* TextButtonView.m in Sources */,
|
||||||
@ -2028,7 +2028,7 @@
|
|||||||
D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */,
|
D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */,
|
||||||
C695A69823C990C200BFB94E /* DoughnutChartView.swift in Sources */,
|
C695A69823C990C200BFB94E /* DoughnutChartView.swift in Sources */,
|
||||||
D29DF2CB21E7BFCC003B2FB9 /* MFSizeThreshold.m in Sources */,
|
D29DF2CB21E7BFCC003B2FB9 /* MFSizeThreshold.m in Sources */,
|
||||||
011D959F240453A1000E3791 /* RuleValueChangeModel.swift in Sources */,
|
011D959F240453A1000E3791 /* RuleAllValueChangedModel.swift in Sources */,
|
||||||
011D95AD2406BB57000E3791 /* FormHolderProtocol.swift in Sources */,
|
011D95AD2406BB57000E3791 /* FormHolderProtocol.swift in Sources */,
|
||||||
946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */,
|
946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */,
|
||||||
01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */,
|
01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */,
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import Foundation
|
|||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String? = FormValidator.defaultGroupName
|
public var groupName: String? = FormValidator.defaultGroupName
|
||||||
public var text: String?
|
public var text: String?
|
||||||
|
public var baseValue: JSONValue?
|
||||||
|
|
||||||
public var isValid: Bool? {
|
public var isValid: Bool? {
|
||||||
didSet {
|
didSet {
|
||||||
@ -60,8 +61,12 @@ import Foundation
|
|||||||
case groupName
|
case groupName
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formFieldValue() -> Any? {
|
public func formFieldValue() -> JSONValue? {
|
||||||
return text
|
if let text = text {
|
||||||
|
return JSONValue(stringLiteral: text)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol {
|
@objcMembers public class CheckboxModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -33,6 +32,7 @@ import Foundation
|
|||||||
|
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String? = FormValidator.defaultGroupName
|
public var groupName: String? = FormValidator.defaultGroupName
|
||||||
|
public var baseValue: JSONValue?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
@ -59,8 +59,8 @@ import Foundation
|
|||||||
|
|
||||||
init(isChecked: Bool = false) {}
|
init(isChecked: Bool = false) {}
|
||||||
|
|
||||||
public func formFieldValue() -> Any? {
|
public func formFieldValue() -> JSONValue? {
|
||||||
return isChecked
|
return JSONValue(booleanLiteral: isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -83,8 +83,11 @@ import UIKit
|
|||||||
return radioModel?.fieldKey
|
return radioModel?.fieldKey
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formFieldValue() -> String? {
|
public func formFieldValue() -> JSONValue? {
|
||||||
return radioModel?.fieldValue
|
if let fieldValue = radioModel?.fieldValue {
|
||||||
|
return JSONValue(stringLiteral: fieldValue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMViewProtocol
|
// MARK: - MVMViewProtocol
|
||||||
|
|||||||
@ -7,22 +7,22 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
|
public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "radioButton"
|
public static var identifier: String = "radioButton"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var state: Bool? = false
|
public var state: Bool? = false
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String? = FormValidator.defaultGroupName
|
public var groupName: String? = FormValidator.defaultGroupName
|
||||||
public var fieldValue: String
|
public var fieldValue: String?
|
||||||
public func formFieldValue() -> Any? {
|
public var baseValue: JSONValue?
|
||||||
return fieldValue
|
|
||||||
}
|
public func formFieldValue() -> JSONValue? {
|
||||||
|
if let fieldValue = fieldValue {
|
||||||
init(_ fieldKey: String, _ fieldValue: String) {
|
return JSONValue(stringLiteral: fieldValue)
|
||||||
self.fieldKey = fieldKey
|
} else {
|
||||||
self.fieldValue = fieldValue
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
|||||||
public var alternateAction: ActionModelProtocol?
|
public var alternateAction: ActionModelProtocol?
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String? = FormValidator.defaultGroupName
|
public var groupName: String? = FormValidator.defaultGroupName
|
||||||
|
public var baseValue: JSONValue?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
@ -29,8 +30,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
|||||||
case groupName
|
case groupName
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formFieldValue() -> Any? {
|
public func formFieldValue() -> JSONValue? {
|
||||||
return state
|
return JSONValue(booleanLiteral: state)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ state: Bool) {
|
public init(_ state: Bool) {
|
||||||
|
|||||||
@ -24,7 +24,8 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func insertMolecule(_ molecule: FormItemProtocol) {
|
public func insertMolecule(_ molecule: FormItemProtocol) {
|
||||||
if let molecule = molecule as? FormFieldProtocol {
|
if var molecule = molecule as? FormFieldProtocol {
|
||||||
|
molecule.baseValue = molecule.formFieldValue()
|
||||||
fieldMolecules.append(molecule)
|
fieldMolecules.append(molecule)
|
||||||
}
|
}
|
||||||
if let molecule = molecule as? FormActionFieldProtocol {
|
if let molecule = molecule as? FormActionFieldProtocol {
|
||||||
|
|||||||
@ -11,5 +11,12 @@ import Foundation
|
|||||||
|
|
||||||
public protocol FormFieldProtocol: FormItemProtocol {
|
public protocol FormFieldProtocol: FormItemProtocol {
|
||||||
var fieldKey: String? { get set }
|
var fieldKey: String? { get set }
|
||||||
func formFieldValue() -> Any?
|
var baseValue: JSONValue? { get set }
|
||||||
|
func formFieldValue() -> JSONValue?
|
||||||
|
}
|
||||||
|
|
||||||
|
extension FormFieldProtocol {
|
||||||
|
var baseValue: JSONValue? {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class RuleValueChangeModel: RulesProtocol {
|
public class RuleAllValueChangedModel: RulesProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "valueChanged"
|
public static var identifier: String = "allValueChanged"
|
||||||
public var ruleType: String = RuleAnyModel.identifier
|
public var ruleType: String = RuleAllValueChangedModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
||||||
return false
|
return formField.baseValue != formField.formFieldValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,10 +10,13 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
||||||
|
|
||||||
|
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String? = FormValidator.defaultGroupName
|
public var groupName: String? = FormValidator.defaultGroupName
|
||||||
private var selectedRadioButton: RadioButton?
|
private var selectedRadioButton: RadioButton?
|
||||||
private var fieldGroupName: String?
|
private var fieldGroupName: String?
|
||||||
|
public var baseValue: JSONValue?
|
||||||
|
|
||||||
init(_ fieldKey: String?) {
|
init(_ fieldKey: String?) {
|
||||||
self.fieldKey = fieldKey
|
self.fieldKey = fieldKey
|
||||||
@ -44,7 +47,7 @@ extension RadioButtonSelectionHelper {
|
|||||||
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
|
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formFieldValue() -> Any? {
|
public func formFieldValue() -> JSONValue? {
|
||||||
return selectedRadioButton?.formFieldValue()
|
return selectedRadioButton?.formFieldValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,8 +121,8 @@ import Foundation
|
|||||||
|
|
||||||
// Helper models
|
// Helper models
|
||||||
try? ModelRegistry.register(RuleRequiredModel.self)
|
try? ModelRegistry.register(RuleRequiredModel.self)
|
||||||
try? ModelRegistry.register(RuleAnyModel.self)
|
try? ModelRegistry.register(RuleAnyValueChangedModel.self)
|
||||||
try? ModelRegistry.register(RuleValueChangeModel.self)
|
try? ModelRegistry.register(RuleAllValueChangedModel.self)
|
||||||
try? ModelRegistry.register(RuleEqualsModel.self)
|
try? ModelRegistry.register(RuleEqualsModel.self)
|
||||||
try? ModelRegistry.register(RuleRegexModel.self)
|
try? ModelRegistry.register(RuleRegexModel.self)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user