fixes
This commit is contained in:
parent
97cf39eaee
commit
1bbfb0390a
@ -57,7 +57,6 @@
|
||||
017BEB382360C6AC0024EF95 /* RadioButtonLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */; };
|
||||
017BEB3C2361EA1D0024EF95 /* MFViewController+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */; };
|
||||
017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB3F23620A230024EF95 /* TextFieldModel.swift */; };
|
||||
017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB4123620AD20024EF95 /* FormModelProtocol.swift */; };
|
||||
017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */; };
|
||||
017BEB48236230DB0024EF95 /* MoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */; };
|
||||
017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; };
|
||||
@ -425,7 +424,6 @@
|
||||
017BEB372360C6AC0024EF95 /* RadioButtonLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioButtonLabel.swift; sourceTree = "<group>"; };
|
||||
017BEB3B2361EA1D0024EF95 /* MFViewController+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFViewController+Model.swift"; sourceTree = "<group>"; };
|
||||
017BEB3F23620A230024EF95 /* TextFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldModel.swift; sourceTree = "<group>"; };
|
||||
017BEB4123620AD20024EF95 /* FormModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormModelProtocol.swift; sourceTree = "<group>"; };
|
||||
017BEB432362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIMoleculeMappingObject+ModelExtension.swift"; sourceTree = "<group>"; };
|
||||
017BEB47236230DB0024EF95 /* MoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeViewProtocol.swift; sourceTree = "<group>"; };
|
||||
017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = "<group>"; };
|
||||
@ -762,7 +760,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */,
|
||||
017BEB4123620AD20024EF95 /* FormModelProtocol.swift */,
|
||||
012A88C3238D86E600FE3DA1 /* CarouselItemModelProtocol.swift */,
|
||||
012A88B0238C880100FE3DA1 /* CarouselPagingModelProtocol.swift */,
|
||||
01EB3683236097C0006832FA /* MoleculeModelProtocol.swift */,
|
||||
@ -1947,7 +1944,6 @@
|
||||
D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */,
|
||||
C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */,
|
||||
0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */,
|
||||
017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */,
|
||||
D2D90B442404789000DD6EC9 /* MoleculeContainerProtocol.swift in Sources */,
|
||||
012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */,
|
||||
D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */,
|
||||
|
||||
@ -33,7 +33,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormAction
|
||||
public var disabledFillColor: Color?
|
||||
public var disabledTextColor: Color?
|
||||
public var disabledBorderColor: Color?
|
||||
public var groupName: String?
|
||||
public var groupName: String? = FormValidator.defaultGroupName
|
||||
|
||||
public func updateEnable(_ enabled: Bool) {
|
||||
self.enabled = enabled
|
||||
@ -82,7 +82,9 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormAction
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||
groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
|
||||
self.style = style
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ import Foundation
|
||||
public var isLocked: Bool?
|
||||
public var isSelected: Bool?
|
||||
public var fieldKey: String?
|
||||
public var isRequired: Bool?
|
||||
public var groupName: String? = FormValidator.defaultGroupName
|
||||
public var text: String?
|
||||
|
||||
public var isValid: Bool? {
|
||||
@ -57,6 +57,7 @@ import Foundation
|
||||
case isValid
|
||||
case isRequired = "required"
|
||||
case text
|
||||
case groupName
|
||||
}
|
||||
|
||||
public func formFieldValue() -> Any? {
|
||||
@ -79,6 +80,10 @@ import Foundation
|
||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||
isValid = try typeContainer.decodeIfPresent(Bool.self, forKey: .isValid)
|
||||
text = try typeContainer.decodeIfPresent(String.self, forKey: .text)
|
||||
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -94,5 +99,6 @@ import Foundation
|
||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||
try container.encodeIfPresent(isValid, forKey: .isValid)
|
||||
try container.encodeIfPresent(text, forKey: .text)
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,9 +197,8 @@ import UIKit
|
||||
@objc deinit {
|
||||
setBothTextDelegates(to: nil)
|
||||
}
|
||||
|
||||
|
||||
@objc public func setBothTextDelegates(to delegate: (UITextFieldDelegate & ObservingTextFieldDelegate)?) {
|
||||
|
||||
observingTextFieldDelegate = delegate
|
||||
uiTextFieldDelegate = delegate
|
||||
}
|
||||
@ -246,7 +245,6 @@ import UIKit
|
||||
}
|
||||
/// Executes on UITextField.textDidBeginEditingNotification
|
||||
@objc func startEditing() {
|
||||
|
||||
isSelected = true
|
||||
textField.becomeFirstResponder()
|
||||
}
|
||||
@ -254,6 +252,7 @@ import UIKit
|
||||
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
||||
@objc func valueChanged() {
|
||||
guard validateEachCharacter else { return }
|
||||
isSelected = true
|
||||
validateTextField()
|
||||
}
|
||||
|
||||
@ -310,7 +309,6 @@ import UIKit
|
||||
defaultValidationBlock()
|
||||
}
|
||||
|
||||
// observingTextFieldDelegate = FormValidator.getFormValidatorFor(delegate: delegateObject?.formHolderDelegate)
|
||||
uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate
|
||||
observingTextFieldDelegate = delegateObject?.observingTextFieldDelegate
|
||||
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: uiTextFieldDelegate)
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers public class TextFieldModel: MoleculeModelProtocol, FormModelProtocol {
|
||||
@objcMembers public class TextFieldModel: MoleculeModelProtocol {
|
||||
|
||||
public static var identifier: String = "textField"
|
||||
public var backgroundColor: Color?
|
||||
|
||||
@ -32,6 +32,7 @@ import Foundation
|
||||
public var disabledCheckColor: Color = Color(uiColor: .mvmCoolGray3)
|
||||
|
||||
public var fieldKey: String?
|
||||
public var groupName: String? = FormValidator.defaultGroupName
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
@ -53,6 +54,7 @@ import Foundation
|
||||
case isRound
|
||||
case isEnabled
|
||||
case action
|
||||
case groupName
|
||||
}
|
||||
|
||||
init(isChecked: Bool = false) {}
|
||||
@ -81,6 +83,9 @@ import Foundation
|
||||
isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false
|
||||
isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? true
|
||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -100,5 +105,6 @@ import Foundation
|
||||
try container.encodeIfPresent(isRound, forKey: .isRound)
|
||||
try container.encodeIfPresent(isEnabled, forKey: .isEnabled)
|
||||
try container.encodeModelIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ import UIKit
|
||||
}
|
||||
|
||||
lazy var radioGroupName: String? = {
|
||||
[unowned self] in return radioModel?.radioGroupName ?? radioModel?.fieldKey
|
||||
[unowned self] in return radioModel?.fieldKey
|
||||
}()
|
||||
|
||||
lazy var radioButtonSelectionHelper: RadioButtonSelectionHelper? = {
|
||||
@ -80,7 +80,7 @@ import UIKit
|
||||
}
|
||||
|
||||
public func formFieldGroupName() -> String? {
|
||||
return radioModel?.radioGroupName
|
||||
return radioModel?.fieldKey
|
||||
}
|
||||
|
||||
public func formFieldValue() -> String? {
|
||||
|
||||
@ -14,8 +14,8 @@ public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
public static var identifier: String = "radioButton"
|
||||
public var backgroundColor: Color?
|
||||
public var state: Bool? = false
|
||||
public var radioGroupName: String?
|
||||
public var fieldKey: String?
|
||||
public var groupName: String? = FormValidator.defaultGroupName
|
||||
public var fieldValue: String
|
||||
public func formFieldValue() -> Any? {
|
||||
return fieldValue
|
||||
|
||||
@ -15,8 +15,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
public var state: Bool = true
|
||||
public var action: ActionModelProtocol?
|
||||
public var alternateAction: ActionModelProtocol?
|
||||
public var required: Bool?
|
||||
public var fieldKey: String?
|
||||
public var groupName: String? = FormValidator.defaultGroupName
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
@ -26,6 +26,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
case required
|
||||
case fieldKey
|
||||
case alternateAction
|
||||
case groupName
|
||||
}
|
||||
|
||||
public func formFieldValue() -> Any? {
|
||||
@ -44,8 +45,10 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||
alternateAction = try typeContainer.decodeModelIfPresent(codingKey: .alternateAction, typeCodingKey: ActionCodingKey.actionType)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
|
||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -55,7 +58,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
try container.encodeModelIfPresent(alternateAction, forKey: .alternateAction)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(state, forKey: .state)
|
||||
try container.encodeIfPresent(required, forKey: .required)
|
||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,9 +11,8 @@ import MVMCore
|
||||
|
||||
@objcMembers public class FormValidator: NSObject {
|
||||
|
||||
static var defaultGroupName: String = "default"
|
||||
var extraValidationBlock: (() -> Bool)?
|
||||
var dummyGroupName = "dummyGroupName"
|
||||
|
||||
var formRules: [FormGroupRule]
|
||||
var delegate: FormHolderProtocol?
|
||||
var fieldMolecules: [FormFieldProtocol] = []
|
||||
@ -75,15 +74,19 @@ import MVMCore
|
||||
// mark Form params
|
||||
@objc public extension FormValidator {
|
||||
@objc func addFormParams(requestParameters: MVMCoreRequestParameters) {
|
||||
requestParameters.add(self.getFormParams())
|
||||
let formButton = getFormButton(forPageType: requestParameters.pageType)
|
||||
let groupName = formButton?.groupName ?? FormValidator.defaultGroupName
|
||||
let formParams = self.getFormParams(forGroup: groupName)
|
||||
requestParameters.add(formParams)
|
||||
}
|
||||
|
||||
@objc func getFormParams() -> [String: Any] {
|
||||
@objc func getFormParams( forGroup groupName: String) -> [String: Any] {
|
||||
var extraParam: [String: Any] = [:]
|
||||
MVMCoreDispatchUtility.performSyncBlock(onMainThread: {
|
||||
for molecule in self.fieldMolecules {
|
||||
if let formFieldName = molecule.fieldKey,
|
||||
let formFieldValue = molecule.formFieldValue() {
|
||||
let formFieldValue = molecule.formFieldValue(),
|
||||
groupName == molecule.groupName {
|
||||
extraParam[formFieldName] = formFieldValue
|
||||
}
|
||||
}
|
||||
@ -91,3 +94,17 @@ import MVMCore
|
||||
return extraParam
|
||||
}
|
||||
}
|
||||
|
||||
// Temporary
|
||||
public extension FormValidator {
|
||||
func getFormButton(forPageType pageType: String?) -> ButtonModel? {
|
||||
for actionItem in formActionMolecules {
|
||||
if let buttonModel = actionItem as? ButtonModel,
|
||||
pageType == (buttonModel.action as? ActionOpenPageModel)?.pageType {
|
||||
return buttonModel
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,8 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol FormActionFieldProtocol: EnableableModelProtocol, FormItemProtocol {
|
||||
var groupName: String? { get set }
|
||||
public protocol FormActionFieldProtocol: EnableableModelProtocol, FormItemProtocol {
|
||||
func updateEnable(_ enabled: Bool)
|
||||
var updateUI: (() -> Void)? { get set }
|
||||
}
|
||||
|
||||
@ -10,6 +10,6 @@ import Foundation
|
||||
|
||||
|
||||
public protocol FormFieldProtocol: FormItemProtocol {
|
||||
var fieldKey: String? { get set }
|
||||
var fieldKey: String? { get set }
|
||||
func formFieldValue() -> Any?
|
||||
}
|
||||
|
||||
@ -9,5 +9,11 @@
|
||||
import Foundation
|
||||
|
||||
public protocol FormItemProtocol {
|
||||
|
||||
static var defaultGroupName: String? { get }
|
||||
var groupName: String? { get set }
|
||||
}
|
||||
extension FormItemProtocol{
|
||||
public static var defaultGroupName: String? {
|
||||
return "default"
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ public class RuleRequiredModel: RulesProtocol {
|
||||
}
|
||||
var valid = true
|
||||
if let valueString = value as? String {
|
||||
valid = valueString.count > 3
|
||||
valid = valueString.count > 0
|
||||
} else if let valueBool = value as? Bool {
|
||||
valid = valueBool
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// FormModelProtocol.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 10/24/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
public protocol FormModelProtocol: ModelProtocol {
|
||||
var required: Bool? { get }
|
||||
var fieldKey: String? { get }
|
||||
var groupName: String? { get }
|
||||
}
|
||||
@ -11,6 +11,7 @@ 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?
|
||||
|
||||
@ -19,13 +20,13 @@ import UIKit
|
||||
}
|
||||
|
||||
public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, formValidator: FormValidator?) -> RadioButtonSelectionHelper {
|
||||
guard let groupName = radioButtonModel.radioGroupName ?? radioButtonModel.fieldKey,
|
||||
guard let groupName = radioButtonModel.fieldKey,
|
||||
let formValidator = formValidator else {
|
||||
return RadioButtonSelectionHelper(radioButtonModel.fieldKey)
|
||||
}
|
||||
|
||||
let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey)
|
||||
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.radioGroupName
|
||||
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey
|
||||
formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper
|
||||
return radioButtonSelectionHelper
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user