updated model with:

removed: titleLabel, feedbackLabel
added: required

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-01-11 15:48:34 -06:00
parent 8444ad15eb
commit 083d767740

View File

@ -9,7 +9,7 @@
import Foundation
@objcMembers open class EntryFieldModel: MoleculeModelProtocol, FormFieldProtocol, FormRuleWatcherFieldProtocol, UIUpdatableModelProtocol {
@objcMembers open class EntryFieldModel: MoleculeModelProtocol, FormFieldProtocol, FormRuleWatcherFieldProtocol, UIUpdatableModelProtocol, ClearableModelProtocol {
//--------------------------------------------------
// MARK: - Properties
@ -29,6 +29,7 @@ import Foundation
public var errorMessage: String?
public var errorTextColor: Color?
public var enabled: Bool = true
public var required: Bool = true
public var readOnly: Bool = false
public var showError: Bool?
public var hideBorders = false
@ -39,20 +40,12 @@ import Foundation
public var groupName: String = FormValidator.defaultGroupName
public var baseValue: AnyHashable?
public var wasInitiallySelected: Bool = false
//text only
//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?
public var title: String?
public var feedback: String?
//used to drive the EntryFieldView UI
public var titleStateLabel: StateLabelModel
public var feedbackStateLabel: StateLabelModel
public var titleStateLabel: FormLabelModel
public var feedbackStateLabel: FormLabelModel
public var isValid: Bool? = true {
didSet { updateUI?() }
@ -85,8 +78,7 @@ import Foundation
case text
case fieldKey
case groupName
case titleLabel
case feedbackLabel
case required
}
//--------------------------------------------------
@ -119,8 +111,15 @@ import Foundation
public init(with text: String) {
self.text = text
baseValue = text
self.titleStateLabel = StateLabelModel(text: "")
self.feedbackStateLabel = StateLabelModel(text: "")
self.titleStateLabel = FormLabelModel(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)
errorTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .errorTextColor)
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
locked = try typeContainer.decodeIfPresent(Bool.self, forKey: .locked)
selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected)
@ -143,24 +143,13 @@ import Foundation
hideBorders = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideBorders) ?? false
baseValue = text
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) {
self.groupName = groupName
}
//Setup the stateLabelModels
if let titleLabel = titleLabel {
self.titleStateLabel = StateLabelModel(model: titleLabel)
} 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 ?? "")
}
self.titleStateLabel = FormLabelModel(text: title ?? "")
self.feedbackStateLabel = FormLabelModel(model: LabelModel(text: feedback ?? "",
fontStyle: FormLabelModel.defaultFontStyle,
textColor: Color(uiColor: .mvmCoolGray6)))
}
public func encode(to encoder: Encoder) throws {
@ -169,9 +158,7 @@ import Foundation
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
try container.encodeIfPresent(title, forKey: .title)
try container.encodeIfPresent(titleLabel, forKey: .titleLabel)
try container.encodeIfPresent(feedback, forKey: .feedback)
try container.encodeIfPresent(feedbackLabel, forKey: .feedbackLabel)
try container.encodeIfPresent(text, forKey: .text)
try container.encodeIfPresent(locked, forKey: .locked)
try container.encodeIfPresent(showError, forKey: .showError)
@ -183,6 +170,7 @@ import Foundation
try container.encode(readOnly, forKey: .readOnly)
try container.encode(enabled, forKey: .enabled)
try container.encode(required, forKey: .required)
try container.encode(hideBorders, forKey: .hideBorders)
}
}