diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 7d938990..bb4d2d97 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -83,6 +83,9 @@ open class DropdownSelect: EntryFieldBase { $0.font = TextStyle.bodyLarge.font } + /// Determines the placement of the helper text. + open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { setNeedsUpdate() } } + open var optionsPicker = UIPickerView() //-------------------------------------------------- @@ -246,6 +249,26 @@ open class DropdownSelect: EntryFieldBase { statusIcon.color = iconColorConfiguration.getColor(self) } + open override func updateHelperLabel(){ + //remove first + helperLabel.removeFromSuperview() + + super.updateHelperLabel() + + //set the helper label position + if helperText != nil { + if helperTextPlacement == .right { + middleStackView.spacing = 12 + middleStackView.distribution = .fillEqually + middleStackView.addArrangedSubview(helperLabel) + } else { + middleStackView.spacing = 0 + middleStackView.distribution = .fill + bottomContainerStackView.addArrangedSubview(helperLabel) + } + } + } + open override func updateAccessibility() { super.updateAccessibility() let selectedOption = selectedOptionLabel.text ?? "" diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 64593441..ea833187 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -60,7 +60,16 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { $0.distribution = .fill } }() - + + internal var middleStackView: UIStackView = { + return UIStackView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .top + } + }() + internal var containerView: UIView = { return UIView().with { $0.translatesAutoresizingMaskIntoConstraints = false @@ -219,6 +228,9 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0) widthConstraint?.priority = .defaultHigh + //add the containerView to the middleStack + middleStackView.addArrangedSubview(containerView) + //add ContainerStackView //this is the horizontal stack that contains //the left, InputContainer, Icons, Buttons @@ -242,11 +254,11 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { bottomContainerStackView.addArrangedSubview(helperLabel) stackView.addArrangedSubview(titleLabel) - stackView.addArrangedSubview(containerView) + stackView.addArrangedSubview(middleStackView) stackView.addArrangedSubview(bottomContainer) stackView.setCustomSpacing(4, after: titleLabel) - stackView.setCustomSpacing(8, after: containerView) + stackView.setCustomSpacing(8, after: middleStackView) stackView.setCustomSpacing(8, after: bottomContainer) stackView diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 327e46d6..49f0cfbc 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -34,15 +34,6 @@ open class InputField: EntryFieldBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - internal var inputFieldStackView: UIStackView = { - return UIStackView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.axis = .horizontal - $0.distribution = .fill - $0.spacing = 12 - } - }() - internal var minWidthConstraint: NSLayoutConstraint? //-------------------------------------------------- @@ -274,13 +265,13 @@ open class InputField: EntryFieldBase { //set the helper label position if helperText != nil { if helperTextPlacement == .right { - inputFieldStackView.spacing = 12 - inputFieldStackView.distribution = .fillEqually - inputFieldStackView.addArrangedSubview(helperLabel) + middleStackView.spacing = 12 + middleStackView.distribution = .fillEqually + middleStackView.addArrangedSubview(helperLabel) } else { - inputFieldStackView.spacing = 0 - inputFieldStackView.distribution = .fill - stackView.addArrangedSubview(helperLabel) + middleStackView.spacing = 0 + middleStackView.distribution = .fill + bottomContainerStackView.addArrangedSubview(helperLabel) } } }