Skip to content

Commit bdd6c2a

Browse files
committed
fixed ordering issue with new inputs handling
1 parent 8cfe2cd commit bdd6c2a

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

iOSFormUtils/Form.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public class Form: UIScrollView {
5454
public var formDelegate: FormDelegate!
5555

5656
/// The current input which has been focused
57-
private var currentInput: FormInput!
58-
59-
/// The form inputs
60-
public var inputs: [FormInput] = [] {
57+
private var currentInput: FormInput! {
6158
didSet {
6259
handleInputsReturnKeys()
6360
}
@@ -79,7 +76,6 @@ public class Form: UIScrollView {
7976

8077
if let input: FormInput = view as? FormInput {
8178
input.formInputDelegate = self
82-
inputs.append(input)
8379
}
8480
}
8581

@@ -118,6 +114,7 @@ public class Form: UIScrollView {
118114
Handles return keys type for inputs
119115
*/
120116
private func handleInputsReturnKeys() {
117+
let inputs = getOrderedInputs()
121118
for input in inputs {
122119
if let textField: UITextField = input as? UITextField {
123120
if textField == inputs.last as? UITextField {
@@ -225,6 +222,24 @@ public class Form: UIScrollView {
225222

226223
return true
227224
}
225+
226+
/**
227+
Gets the ordered inputs of the form
228+
229+
- Return: the ordered inputs
230+
*/
231+
func getOrderedInputs() -> [FormInput] {
232+
var inputs: [FormInput] = []
233+
if let _ = formDelegate {
234+
var inputToAdd: FormInput? = formDelegate.getFirstInput(self)
235+
while nil != inputToAdd {
236+
inputs.append(inputToAdd!)
237+
inputToAdd = formDelegate.getNextInput(self, currentInput: inputToAdd!)
238+
}
239+
}
240+
241+
return inputs
242+
}
228243
}
229244

230245
// MARK: Extensions

iOSFormUtils/ValidatedForm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ValidatedForm: Form {
2020
- Return: validation result
2121
*/
2222
public func validate() -> Bool {
23-
for input in inputs {
23+
for input in getOrderedInputs() {
2424
if (!input.validateFormat()) {
2525
return false
2626
}

0 commit comments

Comments
 (0)