refactored value to be readOnly
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7e2fdb30e3
commit
bb705d8155
@ -37,6 +37,11 @@ open class DropdownSelect: EntryFieldBase {
|
|||||||
/// Allows unique ID to be passed to the element.
|
/// Allows unique ID to be passed to the element.
|
||||||
open var selectId: Int? { didSet { setNeedsUpdate() }}
|
open var selectId: Int? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
/// Current SelectedItem Value
|
||||||
|
open override var value: String? {
|
||||||
|
selectedItem?.value
|
||||||
|
}
|
||||||
|
|
||||||
/// Current SelectedItem
|
/// Current SelectedItem
|
||||||
open var selectedItem: DropdownOptionModel? {
|
open var selectedItem: DropdownOptionModel? {
|
||||||
guard let selectId else { return nil }
|
guard let selectId else { return nil }
|
||||||
@ -228,7 +233,6 @@ open class DropdownSelect: EntryFieldBase {
|
|||||||
|
|
||||||
open func updateSelectedOptionLabel(option: DropdownOptionModel? = nil) {
|
open func updateSelectedOptionLabel(option: DropdownOptionModel? = nil) {
|
||||||
selectedOptionLabel.text = option?.text ?? ""
|
selectedOptionLabel.text = option?.text ?? ""
|
||||||
value = option?.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateErrorLabel() {
|
open override func updateErrorLabel() {
|
||||||
@ -278,6 +282,7 @@ extension DropdownSelect: UIPickerViewDelegate, UIPickerViewDataSource {
|
|||||||
guard options.count > row else { return }
|
guard options.count > row else { return }
|
||||||
selectId = row
|
selectId = row
|
||||||
updateSelectedOptionLabel(option: options[row])
|
updateSelectedOptionLabel(option: options[row])
|
||||||
|
sendActions(for: .valueChanged)
|
||||||
self.onItemSelected?(row, options[row])
|
self.onItemSelected?(row, options[row])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,15 +201,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
open var inputId: String? { didSet { setNeedsUpdate() } }
|
open var inputId: String? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// The text of this textField.
|
/// The text of this textField.
|
||||||
internal var _value: String?
|
|
||||||
open var value: String? {
|
open var value: String? {
|
||||||
get { _value }
|
get { fatalError("must be read from subclass")}
|
||||||
set {
|
|
||||||
if let newValue, newValue != _value {
|
|
||||||
_value = newValue
|
|
||||||
sendActions(for: .valueChanged)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open var defaultValue: AnyHashable? { didSet { setNeedsUpdate() } }
|
open var defaultValue: AnyHashable? { didSet { setNeedsUpdate() } }
|
||||||
@ -306,7 +299,6 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
transparentBackground = false
|
transparentBackground = false
|
||||||
width = nil
|
width = nil
|
||||||
inputId = nil
|
inputId = nil
|
||||||
value = nil
|
|
||||||
defaultValue = nil
|
defaultValue = nil
|
||||||
required = false
|
required = false
|
||||||
readOnly = false
|
readOnly = false
|
||||||
|
|||||||
@ -36,7 +36,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// Enum used to describe the input type.
|
/// Enum used to describe the input type.
|
||||||
public enum FieldType: String, CaseIterable {
|
public enum FieldType: String, CaseIterable {
|
||||||
case text, number, calendar, inlineAction, password, creditCard, tel, date, securityCode
|
case text, number, inlineAction, password, creditCard, tel, date, securityCode
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -84,26 +84,16 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
open var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } }
|
open var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// The text of this TextField.
|
/// The text of this TextField.
|
||||||
private var _text: String?
|
|
||||||
open var text: String? {
|
open var text: String? {
|
||||||
get { _text }
|
get { textField.text }
|
||||||
set {
|
set {
|
||||||
if let newValue, newValue != _text {
|
textField.text = newValue
|
||||||
_text = newValue
|
|
||||||
textField.text = newValue
|
|
||||||
value = newValue
|
|
||||||
}
|
|
||||||
setNeedsUpdate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The value of this textField.
|
/// Value for the textField
|
||||||
open override var value: String? {
|
open override var value: String? {
|
||||||
didSet {
|
textField.text
|
||||||
if text != value {
|
|
||||||
text = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _showError: Bool = false
|
var _showError: Bool = false
|
||||||
@ -172,10 +162,10 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
||||||
textField
|
textField
|
||||||
.textPublisher
|
.textPublisher
|
||||||
.sink { [weak self] text in
|
.sink { [weak self] newText in
|
||||||
self?.value = text
|
self?.text = newText
|
||||||
self?.sendActions(for: .valueChanged)
|
self?.sendActions(for: .valueChanged)
|
||||||
|
if newText.isEmpty { self?.passwordActionType = .show }
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
stackView.addArrangedSubview(successLabel)
|
stackView.addArrangedSubview(successLabel)
|
||||||
@ -264,8 +254,8 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
textField.isSecureTextEntry = false
|
textField.isSecureTextEntry = false
|
||||||
|
|
||||||
var minWidth: CGFloat = 40.0
|
var minWidth: CGFloat = 40.0
|
||||||
var iconName: Icon.Name?
|
var leftIconName: Icon.Name?
|
||||||
var actionLinkModel: InputField.TextLinkModel?
|
var actionModel: InputField.TextLinkModel?
|
||||||
var toolTipModel: Tooltip.TooltipModel?
|
var toolTipModel: Tooltip.TooltipModel?
|
||||||
|
|
||||||
switch fieldType {
|
switch fieldType {
|
||||||
@ -275,14 +265,22 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
case .number:
|
case .number:
|
||||||
break
|
break
|
||||||
|
|
||||||
case .calendar:
|
|
||||||
break
|
|
||||||
|
|
||||||
case .inlineAction:
|
case .inlineAction:
|
||||||
minWidth = 102.0
|
minWidth = 102.0
|
||||||
|
|
||||||
case .password:
|
case .password:
|
||||||
textField.isSecureTextEntry = true
|
let isHide = passwordActionType == .hide
|
||||||
|
let buttonText = isHide ? hidePasswordButtonText : showPasswordButtonText
|
||||||
|
let isSecureTextEntry = !isHide
|
||||||
|
let nextPasswordActionType = passwordActionType.toggle()
|
||||||
|
if let text, !text.isEmpty {
|
||||||
|
actionModel = .init(text: buttonText,
|
||||||
|
onClick: { [weak self] _ in
|
||||||
|
guard let self else { return }
|
||||||
|
self.passwordActionType = nextPasswordActionType
|
||||||
|
})
|
||||||
|
textField.isSecureTextEntry = isSecureTextEntry
|
||||||
|
}
|
||||||
minWidth = 62.0
|
minWidth = 62.0
|
||||||
|
|
||||||
case .creditCard:
|
case .creditCard:
|
||||||
@ -302,13 +300,14 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
//leftIcon
|
//leftIcon
|
||||||
leftIcon.surface = surface
|
leftIcon.surface = surface
|
||||||
leftIcon.color = iconColorConfiguration.getColor(self)
|
leftIcon.color = iconColorConfiguration.getColor(self)
|
||||||
leftIcon.name = iconName
|
leftIcon.name = leftIconName
|
||||||
leftIcon.isHidden = iconName == nil
|
leftIcon.isHidden = leftIconName == nil
|
||||||
|
|
||||||
//actionLink
|
//actionLink
|
||||||
actionTextLink.surface = surface
|
actionTextLink.surface = surface
|
||||||
if let actionTextLinkModel = actionLinkModel {
|
if let actionModel {
|
||||||
actionTextLink.text = actionTextLinkModel.text
|
actionTextLink.text = actionModel.text
|
||||||
|
actionTextLink.onClick = actionModel.onClick
|
||||||
actionTextLink.isHidden = false
|
actionTextLink.isHidden = false
|
||||||
containerStackView.setCustomSpacing(VDSLayout.space2X, after: statusIcon)
|
containerStackView.setCustomSpacing(VDSLayout.space2X, after: statusIcon)
|
||||||
} else {
|
} else {
|
||||||
@ -330,4 +329,21 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
//tooltip
|
//tooltip
|
||||||
self.tooltipModel = toolTipModel
|
self.tooltipModel = toolTipModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Password
|
||||||
|
//--------------------------------------------------
|
||||||
|
enum PasswordAction {
|
||||||
|
case show, hide
|
||||||
|
|
||||||
|
func toggle() -> PasswordAction {
|
||||||
|
self == .hide ? .show : .hide
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal var passwordActionType: PasswordAction = .show { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open var hidePasswordButtonText: String = "Hide" { didSet { setNeedsUpdate() } }
|
||||||
|
open var showPasswordButtonText: String = "Show" { didSet { setNeedsUpdate() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -102,24 +102,16 @@ open class TextArea: EntryFieldBase {
|
|||||||
/// The text of this TextArea.
|
/// The text of this TextArea.
|
||||||
private var _text: String?
|
private var _text: String?
|
||||||
open var text: String? {
|
open var text: String? {
|
||||||
get { _text }
|
get { textView.text }
|
||||||
set {
|
set {
|
||||||
if let newValue, newValue != _text {
|
textView.text = newValue
|
||||||
_text = newValue
|
|
||||||
textView.text = newValue
|
|
||||||
value = newValue
|
|
||||||
}
|
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The value of this textField.
|
/// The value of this textField.
|
||||||
open override var value: String? {
|
open override var value: String? {
|
||||||
didSet {
|
return textView.text
|
||||||
if text != value {
|
|
||||||
text = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UITextView shown in the TextArea.
|
/// UITextView shown in the TextArea.
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public protocol FormFieldable {
|
|||||||
var inputId: String? { get set }
|
var inputId: String? { get set }
|
||||||
|
|
||||||
/// Value for the Form Field.
|
/// Value for the Form Field.
|
||||||
var value: ValueType? { get set }
|
var value: ValueType? { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Protocol for FormFieldable that require internal validation.
|
/// Protocol for FormFieldable that require internal validation.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user