Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation support to SplitRow #37

Closed
kmav opened this issue Aug 25, 2019 · 5 comments
Closed

Add validation support to SplitRow #37

kmav opened this issue Aug 25, 2019 · 5 comments

Comments

@kmav
Copy link

kmav commented Aug 25, 2019

Hello.

Thank you for the very useful SplitRow extension.

How I can validate text content (required) of left TextRow?
I added validation logic on rowLeft (TextRow) : row.onRowValidationChanged(self.validateNoteButtonRow)

func validateNoteButtonRow(_ cell: TextCell, _ row: TextRow) {
if let noteRow = self.form.rowBy(tag: "addNote") as? SplitRow<TextRow,ButtonRow> {
let rowIndex = noteRow.indexPath!.row
while noteRow.section!.count > rowIndex + 1 && noteRow.section?[rowIndex + 1] is LabelRow {
noteRow.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 = { 30 }
$0.cell.backgroundColor = .red
$0.cell.textLabel?.tintColor = .white
}
let indexPath = noteRow.indexPath!.row + index + 1
noteRow.section?.insert(labelRow, at: indexPath)
}
}
} else {
Log.debug("Validation: SplitRow nil")
}
}
Screenshot 2019-08-25 at 22 21 27

I would like:

  1. to do it as the Eureka example that pop ups a label with message below of the SplitRow: I succeeded with that using your hints from another issue. The validation is activated when starting to type text.

  2. To make the above validation to execute when I call self.form.validate() because the user can press an ADD button to add what is in TextRow on a list. When the user press ADD, I would like to force validation. For the moment, when I call self.form.validate() only validations created in other basic fields of the form are called. Maybe SplitRow validation is not called because it is included/defined only in let TextRow? Another thing that I tried was to force call validation code but it did not work... Code below did not succeeded to call validation of TextRow field:

// if let noteRow = self.form.rowBy(tag: "addNote") as? SplitRow<TextRow,ButtonRow>, let row = noteRow.rowLeft as TextRow? {
// Log.debug("VitalSignsViewController: checkIsEmpty: note field/row found")
// self.validateNoteButtonRow(row.cell, row)
// }

Thank you very much in advance :)

@kmav kmav changed the title Validate SplitRow<TextRow,ButtonRow> text in TextRow How to Validate SplitRow<TextRow,ButtonRow> text in TextRow Aug 25, 2019
@marbetschar
Copy link
Collaborator

@kmav seems like there's indeed a connection missing - validation requests are not passed through SplitRow at all atm. If I understand you correctly, you'd like to call form.validate() and SplitRow should pass the request down the chain to rowLeft and rowRight. Is this correct?

Unfortunately I do not have a lot of spare time currently, but I'm happy to merge a Pull Request if you want to give it a try. There is already a request hanging - so you might want to join forces with @GaDaXaRa to get that validation stuff finally done and merged:

#31

Since I do not have any such validation requirements, its kinda hard for me to judge if the solution is "correct" - in the sense of generally usefull for others as well.

@kmav
Copy link
Author

kmav commented Aug 27, 2019

Thank you all of you for taking attention to this.

From my comment above (1) it results that left row validation propagates up to SplitRow when I type text and then delete it to have empty string. In that case, a new row pop ups below with the validation alert string "This field is required".
However, (2) when the control is outside of SplitRow definition and needs to call form.validate() , the validation of leftRow is not activated. (BTW, I have a simple TextRow before SplitRow and that validation is activated.)
I tried this either by defining the validation at leftRow TextRow level, either at SpliRow higher level. It did not work in both implementations.

Do you mean that the SplitRow validation is not fully implemented yet?

@marbetschar
Copy link
Collaborator

@kmav exactly. Validation is not integrated in SplitRow, since the original approach was to leave it up to the child rows. This also means there is no validation request passing through SplitRow coming from the form.

I can see how this leads to inconsistent behavior which in turn leads to confusion. However, I‘m not really familiar with the validation possibilities in Eureka and don‘t have any spare time right now to wrap my head around.

Feel free to give it a try if you like, I‘m happily merge a PR.

@marbetschar marbetschar changed the title How to Validate SplitRow<TextRow,ButtonRow> text in TextRow Add validation support to SplitRow Nov 12, 2019
@Nicopdev
Copy link

Nicopdev commented Dec 9, 2019

The Validation should work like this: if the Cells that are in the SplitRow are both valid, then the SplitRow should return valid.

@marbetschar
Copy link
Collaborator

Fixed by #48.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants