updated model with:
removed: titleLabel, feedbackLabel added: required Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
8444ad15eb
commit
083d767740
@ -9,7 +9,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
@objcMembers open class EntryFieldModel: MoleculeModelProtocol, FormFieldProtocol, FormRuleWatcherFieldProtocol, UIUpdatableModelProtocol {
|
@objcMembers open class EntryFieldModel: MoleculeModelProtocol, FormFieldProtocol, FormRuleWatcherFieldProtocol, UIUpdatableModelProtocol, ClearableModelProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -29,6 +29,7 @@ import Foundation
|
|||||||
public var errorMessage: String?
|
public var errorMessage: String?
|
||||||
public var errorTextColor: Color?
|
public var errorTextColor: Color?
|
||||||
public var enabled: Bool = true
|
public var enabled: Bool = true
|
||||||
|
public var required: Bool = true
|
||||||
public var readOnly: Bool = false
|
public var readOnly: Bool = false
|
||||||
public var showError: Bool?
|
public var showError: Bool?
|
||||||
public var hideBorders = false
|
public var hideBorders = false
|
||||||
@ -39,20 +40,12 @@ import Foundation
|
|||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
public var baseValue: AnyHashable?
|
public var baseValue: AnyHashable?
|
||||||
public var wasInitiallySelected: Bool = false
|
public var wasInitiallySelected: Bool = false
|
||||||
|
public var title: String?
|
||||||
//text only
|
public var feedback: String?
|
||||||
//Used for re-encoding what was decoded
|
|
||||||
private var title: String?
|
|
||||||
private var feedback: String?
|
|
||||||
|
|
||||||
//label models
|
|
||||||
//Used for re-encoding what was decoded
|
|
||||||
private var titleLabel: LabelModel?
|
|
||||||
private var feedbackLabel: LabelModel?
|
|
||||||
|
|
||||||
//used to drive the EntryFieldView UI
|
//used to drive the EntryFieldView UI
|
||||||
public var titleStateLabel: StateLabelModel
|
public var titleStateLabel: FormLabelModel
|
||||||
public var feedbackStateLabel: StateLabelModel
|
public var feedbackStateLabel: FormLabelModel
|
||||||
|
|
||||||
public var isValid: Bool? = true {
|
public var isValid: Bool? = true {
|
||||||
didSet { updateUI?() }
|
didSet { updateUI?() }
|
||||||
@ -85,8 +78,7 @@ import Foundation
|
|||||||
case text
|
case text
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
case titleLabel
|
case required
|
||||||
case feedbackLabel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -119,8 +111,15 @@ import Foundation
|
|||||||
public init(with text: String) {
|
public init(with text: String) {
|
||||||
self.text = text
|
self.text = text
|
||||||
baseValue = text
|
baseValue = text
|
||||||
self.titleStateLabel = StateLabelModel(text: "")
|
self.titleStateLabel = FormLabelModel(text: "")
|
||||||
self.feedbackStateLabel = StateLabelModel(text: "")
|
self.feedbackStateLabel = FormLabelModel(text: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializers
|
||||||
|
//--------------------------------------------------
|
||||||
|
public func clear() {
|
||||||
|
self.text = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -136,6 +135,7 @@ import Foundation
|
|||||||
errorMessage = try typeContainer.decodeIfPresent(String.self, forKey: .errorMessage)
|
errorMessage = try typeContainer.decodeIfPresent(String.self, forKey: .errorMessage)
|
||||||
errorTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .errorTextColor)
|
errorTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .errorTextColor)
|
||||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
||||||
|
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) ?? true
|
||||||
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
||||||
locked = try typeContainer.decodeIfPresent(Bool.self, forKey: .locked)
|
locked = try typeContainer.decodeIfPresent(Bool.self, forKey: .locked)
|
||||||
selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected)
|
selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected)
|
||||||
@ -143,24 +143,13 @@ import Foundation
|
|||||||
hideBorders = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideBorders) ?? false
|
hideBorders = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideBorders) ?? false
|
||||||
baseValue = text
|
baseValue = text
|
||||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||||
titleLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .titleLabel)
|
|
||||||
feedbackLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .feedbackLabel)
|
|
||||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||||
self.groupName = groupName
|
self.groupName = groupName
|
||||||
}
|
}
|
||||||
|
self.titleStateLabel = FormLabelModel(text: title ?? "")
|
||||||
//Setup the stateLabelModels
|
self.feedbackStateLabel = FormLabelModel(model: LabelModel(text: feedback ?? "",
|
||||||
if let titleLabel = titleLabel {
|
fontStyle: FormLabelModel.defaultFontStyle,
|
||||||
self.titleStateLabel = StateLabelModel(model: titleLabel)
|
textColor: Color(uiColor: .mvmCoolGray6)))
|
||||||
} else {
|
|
||||||
self.titleStateLabel = StateLabelModel(text: title ?? "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if let feedBackLabel = feedbackLabel {
|
|
||||||
self.feedbackStateLabel = StateLabelModel(model: feedBackLabel)
|
|
||||||
} else { //feedback is the model for the error
|
|
||||||
self.feedbackStateLabel = StateLabelModel(text: feedback ?? "")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
@ -169,9 +158,7 @@ import Foundation
|
|||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encodeIfPresent(title, forKey: .title)
|
try container.encodeIfPresent(title, forKey: .title)
|
||||||
try container.encodeIfPresent(titleLabel, forKey: .titleLabel)
|
|
||||||
try container.encodeIfPresent(feedback, forKey: .feedback)
|
try container.encodeIfPresent(feedback, forKey: .feedback)
|
||||||
try container.encodeIfPresent(feedbackLabel, forKey: .feedbackLabel)
|
|
||||||
try container.encodeIfPresent(text, forKey: .text)
|
try container.encodeIfPresent(text, forKey: .text)
|
||||||
try container.encodeIfPresent(locked, forKey: .locked)
|
try container.encodeIfPresent(locked, forKey: .locked)
|
||||||
try container.encodeIfPresent(showError, forKey: .showError)
|
try container.encodeIfPresent(showError, forKey: .showError)
|
||||||
@ -183,6 +170,7 @@ import Foundation
|
|||||||
|
|
||||||
try container.encode(readOnly, forKey: .readOnly)
|
try container.encode(readOnly, forKey: .readOnly)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
|
try container.encode(required, forKey: .required)
|
||||||
try container.encode(hideBorders, forKey: .hideBorders)
|
try container.encode(hideBorders, forKey: .hideBorders)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user