EurekaCommunity / SplitRow

A row for Eureka to put two rows side by side into the same UITableViewCell
MIT License
56 stars 27 forks source link

Add validation support to SplitRow #37

Closed kmav closed 3 years ago

kmav commented 5 years ago

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 :)

marbetschar commented 5 years ago

@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:

https://github.com/EurekaCommunity/SplitRow/pull/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 commented 5 years ago

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 commented 5 years ago

@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.

Nicopdev commented 4 years ago

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

marbetschar commented 3 years ago

Fixed by #48.