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

How to get value of SplitRow after submitting form #14

Closed alonreptor closed 6 years ago

alonreptor commented 6 years ago

For Eureka rows:

    // Get the value of a single row
    let row: DateInlineRow? = form.rowBy(tag: "date")
    let dateValue = row?.value

but i cant get it for SplitRow

Please advise

marbetschar commented 6 years ago

@alonreptor it works quite the same way for SplitRow. The only difference is, you get a value of type SplitRowValue<L,R> back, which is a container object holding the values of the embedded rows.

that said, you can access the values like follows:

let row = form.rowBy(tag: "splitRowTag") as? SplitRow<PushRow<String>,DateRow>
let leftValue = row?.value?.left
let rightValue = row?.value?.right

Closing the issue for now. feel free to reopen if it does not work out.

pilloom commented 5 years ago

I use SplitRow, I need to obtain values trough self.form.values(), when i do:

    let formvalues = self.form.values()
    let some_answer = formvalues["ingredients"]
    print(some_answer)

i obtain this:

Optional(Optional([Optional(EurekaTest.SplitRowValue<Swift.Int, Swift.String>(left: Optional(1600), right: Optional("Flour"))), Optional(EurekaTest.SplitRowValue<Swift.Int, Swift.String>(left: Optional(360), right: Optional("Water")))]))

How can i get the values L,F for each row?

if i cast

let some_answer = formvalues["ingredients"] as? SplitRow<String,String>

some_answer return nil

marbetschar commented 5 years ago

@pilloom it looks like you have a value of the type SplitRowValue<Int, String>. Try:

let some_answer = formvalues["ingredients"] as? SplitRowValue<Int, String>
print("leftValue:", some_answer?.left, "rightValue:", some_answer?.right)
masliev commented 5 years ago

@marbetschar Could you please give me an advice. I can't get the values from my SplitRow. My form:

        MultivaluedSection(multivaluedOptions: [.Insert, .Delete],
                           header: "Language you want to learn",
                           footer: "Select language and level") {
                            $0.tag = "want_to_learn_languages"
                            $0.multivaluedRowToInsertAt = { index in
                                return SplitRow<ActionSheetRow<String>, ActionSheetRow<String>>(){
                                    $0.rowLeft = ActionSheetRow<String>(){
                                        $0.options = ["English", "Spanish", "Portuguese", "Chinese", "German", "French", "Italian"]
                                    }

                                    $0.rowRight = ActionSheetRow<String>(){
                                        $0.options = ["Beginner", "Intermediate", "Fluent"]
                                    }
                                }
                            }
                            $0 <<< SplitRow<ActionSheetRow<String>, ActionSheetRow<String>>(){
                                $0.rowLeft = ActionSheetRow<String>(){
                                    $0.options = ["English", "Spanish", "Portuguese", "Chinese", "German", "French", "Italian"]
                                }

                                $0.rowRight = ActionSheetRow<String>(){
                                    $0.title = "Select level"
                                    $0.options = ["Beginner", "Intermediate", "Fluent"]
                                }
                            }
    }

This : var values = self.form.values() let result = values["want_to_learn_languages"]

Return:

Optional(Optional([Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner"))), Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner")))]))

But i can't unwrap it in any ways.

I tried: let result = values["want_to_learn_languages"] as? SplitRowValue<String, String>

let result = values["want_to_learn_languages"] as? SplitRow<ActionSheetRow, ActionSheetRow>

let result = values["want_to_learn_languages"] as? SplitRowValue<ActionSheetRow, ActionSheetRow>

and some more, but everytime i get nil

marbetschar commented 5 years ago

@masliev I assume you are running into issues because of the MultivaluedSection. Therefore the values["want_to_learn_languages"] may contain multiple rows - and therefore values. Or in other words, I think you should expect an array there.

That said, try the following (untested):

let result = values["want_to_learn_languages"] as? [SplitRowValue<ActionSheetRow<String>, ActionSheetRow<String>>]

UPDATE: A closer look at your print does indeed return an array - it's just not that easy to see:

Optional(Optional(
[
Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner"))), Optional(SplitRow.SplitRowValue<Swift.String, Swift.String>(left: Optional("German"), right: Optional("Beginner")))
]
))

From reading that output more carefully, it should work like this:

let result = values["want_to_learn_languages"] as? [SplitRowValue<String, String>]
masliev commented 5 years ago

@marbetschar Many thanks sir, it works perfectly!!! Also thank you for the quick response.

amsubhanTV commented 3 years ago

how can we get Split row left and right values dynamically without specifying Left and Rights types (SplitRowValue<String,Double>).

For example if i have 5 different rows of split rows (which means total form items would be 10) so how can i get values of each row in 'String?'. Currently I have to iterate over all 5 rows and check all possible combinations for SplitRowValues like SplitRowValue<Double, Double>, SplitRowValue<String, Double>, SplitRowValue<Double, String> and so on.

marbetschar commented 3 years ago

If I understand your question correct, then the short answer is: You can't.

That's how static typed languages such as Swift work by design: You need to provide the type at compile time and if you want to convert a Double to a String, you need to tell the compiler how to do that.

So from the compilers point of view, each of the following represents a unique type - and there is no such thing such as a "subpart of a type":