|
|
|
@ -8,21 +8,8 @@ struct AppFormAppearance { |
|
|
|
|
static func textArea(tag: String? = .none, callback: @escaping (TextAreaRow) -> Void) -> TextAreaRow { |
|
|
|
|
let textArea = TextAreaRow(tag) { |
|
|
|
|
$0.title = "" |
|
|
|
|
}.onRowValidationChanged { cell, row in |
|
|
|
|
let rowIndex = row.indexPath!.row |
|
|
|
|
while row.section!.count > rowIndex + 1 && row.section?[rowIndex + 1] is LabelRow { |
|
|
|
|
row.section?.remove(at: rowIndex + 1) |
|
|
|
|
} |
|
|
|
|
if !row.isValid { |
|
|
|
|
for (index, validationMsg) in row.validationErrors.map({ $0.msg }).enumerated() { |
|
|
|
|
let labelRow = LabelRow { |
|
|
|
|
$0.title = validationMsg |
|
|
|
|
$0.cell.height = { 20 } |
|
|
|
|
$0.cell.textLabel?.textColor = .red |
|
|
|
|
} |
|
|
|
|
row.section?.insert(labelRow, at: row.indexPath!.row + index + 1) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onRowValidationChanged { |
|
|
|
|
AppFormAppearance.onRowValidationChanged(baseCell: $0.0, row: $0.1) |
|
|
|
|
} |
|
|
|
|
callback(textArea) |
|
|
|
|
return textArea |
|
|
|
@ -35,21 +22,8 @@ struct AppFormAppearance { |
|
|
|
|
if !row.isValid { |
|
|
|
|
cell.textField?.textColor = .red |
|
|
|
|
} |
|
|
|
|
}.onRowValidationChanged { cell, row in |
|
|
|
|
let rowIndex = row.indexPath!.row |
|
|
|
|
while row.section!.count > rowIndex + 1 && row.section?[rowIndex + 1] is LabelRow { |
|
|
|
|
row.section?.remove(at: rowIndex + 1) |
|
|
|
|
} |
|
|
|
|
if !row.isValid { |
|
|
|
|
for (index, validationMsg) in row.validationErrors.map({ $0.msg }).enumerated() { |
|
|
|
|
let labelRow = LabelRow { |
|
|
|
|
$0.title = validationMsg |
|
|
|
|
$0.cell.height = { 20 } |
|
|
|
|
$0.cell.textLabel?.textColor = .red |
|
|
|
|
} |
|
|
|
|
row.section?.insert(labelRow, at: row.indexPath!.row + index + 1) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onRowValidationChanged { |
|
|
|
|
AppFormAppearance.onRowValidationChanged(baseCell: $0.0, row: $0.1) |
|
|
|
|
} |
|
|
|
|
callback(textField) |
|
|
|
|
return textField |
|
|
|
@ -62,26 +36,30 @@ struct AppFormAppearance { |
|
|
|
|
if !row.isValid { |
|
|
|
|
cell.textField?.textColor = .red |
|
|
|
|
} |
|
|
|
|
}.onRowValidationChanged { cell, row in |
|
|
|
|
let rowIndex = row.indexPath!.row |
|
|
|
|
while row.section!.count > rowIndex + 1 && row.section?[rowIndex + 1] is LabelRow { |
|
|
|
|
row.section?.remove(at: rowIndex + 1) |
|
|
|
|
} |
|
|
|
|
if !row.isValid { |
|
|
|
|
for (index, validationMsg) in row.validationErrors.map({ $0.msg }).enumerated() { |
|
|
|
|
let labelRow = LabelRow { |
|
|
|
|
$0.title = validationMsg |
|
|
|
|
$0.cell.height = { 20 } |
|
|
|
|
$0.cell.textLabel?.textColor = .red |
|
|
|
|
} |
|
|
|
|
row.section?.insert(labelRow, at: row.indexPath!.row + index + 1) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onRowValidationChanged { |
|
|
|
|
AppFormAppearance.onRowValidationChanged(baseCell: $0.0, row: $0.1) |
|
|
|
|
} |
|
|
|
|
callback(textField) |
|
|
|
|
return textField |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func onRowValidationChanged(baseCell: BaseCell, row: BaseRow) { |
|
|
|
|
let rowIndex = row.indexPath!.row |
|
|
|
|
while row.section!.count > rowIndex + 1 && row.section?[rowIndex + 1] is LabelRow { |
|
|
|
|
row.section?.remove(at: rowIndex + 1) |
|
|
|
|
} |
|
|
|
|
if !row.isValid { |
|
|
|
|
for (index, validationMsg) in row.validationErrors.map({ $0.msg }).enumerated() { |
|
|
|
|
let labelRow = LabelRow { |
|
|
|
|
$0.title = validationMsg |
|
|
|
|
$0.cell.height = { 20 } |
|
|
|
|
$0.cell.textLabel?.textColor = .red |
|
|
|
|
} |
|
|
|
|
row.section?.insert(labelRow, at: row.indexPath!.row + index + 1) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func button(_ title: String? = .none, callback: @escaping (ButtonRow) -> Void) -> ButtonRow { |
|
|
|
|
let button = ButtonRow(title) |
|
|
|
|
.cellUpdate { cell, _ in |
|
|
|
|