EurekaCommunity/SplitRow

Selecting an option from PushRow doesn't present the value back on rowLeft

alonreptor opened this issue · 11 comments

Please advise

@alonreptor please make sure you are not adding any onChange handler in the embedded PushRow, since SplitRow relies on this to get notified about changes.

If you need to listen for changes, you should do so by adding an onChange handler on the SplitRow itself.

Does this fix your issue?

Thanks for the quick response.

I tried:
.onChange{ print($0.value?.left)}
after SplitRow... but with no success

is there an example somewhere?

there is an example in the readme: https://github.com/EurekaCommunity/SplitRow

and if you download the repo, you can run the Example app which contains several examples in the ViewController:

https://github.com/EurekaCommunity/SplitRow/blob/master/Example/ViewController.swift

@alonreptor are you setting a tag value on rowLeft? I found during my own development that if I had a tag value set on rowLeft, the value was getting cleared out whenever I changed the value of rowRight. In my case, rowLeft is an ActionSheet and rowRight is an EmailRow

Thanks All!
@kamerc, I took your advise and simply changed the type of rowLeft to an ActionSheet. Now values are presented after selecting.

@alonreptor can you please provide thecode which does not work as expected on your end?

@alonreptor, sorry misunderstood your last post. Thought that it still does not work. I‘ll close this issue for now. Feel free to get in contact if you run in further problems.

@marbetschar just replace type of row: ActionSheetRow back to pushRow

` func buildSectionSamples(form:Form) {

    form
        +++ MultivaluedSection(
        multivaluedOptions: [.Insert,.Delete,],
        header: "Samples",
        footer: ""){
            $0.multivaluedRowToInsertAt = { _ in
                return SplitRow<ActionSheetRow<String>,TextRow>(){
                    $0.title = "Sample"
                    $0.rowLeftPercentage = 0.7
                    $0.rowLeft = ActionSheetRow<String>(){
                        $0.tag = "sampleleft"
                        $0.options = self.sampleList as! [String]
                        $0.value = "Select Sample"
                    }
                    $0.rowRight = TextRow(){
                        $0.tag = "Quantity"
                        $0.placeholder = "Quantity"
                        }.cellUpdate{ cell, row in
                            cell.textField?.clearButtonMode = .whileEditing
                            cell.textField?.textAlignment = .right
                    }
                }
            }
            guard let row = $0.multivaluedRowToInsertAt?(0) else{ return }
            $0 <<< row
    }
}`

Below you'll find a fixed version, using PushRow. Please note that, as @kamerc pointed out, SplitRow uses preconfigured tags for the embedded rows to set the new values correctly. Therefore, if you need a tag, you should set it for the entire SplitRow.

form
	+++ MultivaluedSection(
		multivaluedOptions: [.Insert,.Delete,],
		header: "Samples",
		footer: ""){
			$0.multivaluedRowToInsertAt = { _ in
				return SplitRow<PushRow<String>,TextRow>(){
					$0.tag = "sampleQuantity" //sets the tag for the entire SplitRow
					$0.title = "Sample"
					$0.rowLeftPercentage = 0.7
					
					$0.rowLeft = PushRow<String>(){
						$0.options = ["a","b","c"]
						$0.value = "Select Sample"
					}
					
					$0.rowRight = TextRow(){
						$0.placeholder = "Quantity"
					}.cellUpdate{ cell, row in
						cell.textField?.clearButtonMode = .whileEditing
						cell.textField?.textAlignment = .right
					}
				
				// use an onChange handler on the SplitRow to
				// get notified whenever an embedded row changes its value
				}.onChange{ row in
					print(row.tag,":didChange:value:",row.value)
				}
			}
			guard let row = $0.multivaluedRowToInsertAt?(0) else{ return }
			$0 <<< row
	}

@marbetschar Thank you very much!