Search code examples
swifteureka-forms

Eureka-ios: How to change $0.options by a if statment


I need to change a row's options according to another row which user selected.

I use this code and it didn't change.

<<< PushRow<String>(kEncryption) {
                $0.title = "Encryption"
                if let r1 : PushRow<aType> = form.rowBy(tag: kProxyFormType), let a = r1.value?.isA, let b = r1.value?.isB {
                        print(a)
                        if (a) {
                            $0.options = ["1","2","3"]
                        }
                        else if (b) {
                            $0.options = ["4","5","6"]
                        }
                    }

Whatever I change the aType Row,the pushrow will always be empty.
I add a print function add this function is not called at all.
How can I change this code make it work?


Solution

  • The other way round, change the options of PushRow<String> in the onChange closure of PushRow<aType>, something like

    <<< PushRow<aType>(kProxyFormType) { 
       ...
    }.onChange { row in 
        if let encryptionRow = self.form.rowBy(tag: kEncryption) as? PushRow<String> {
           if row.value?.isA {
               encryptionRow.options = ["1","2","3"]
           } else if row.value?.isB {
               encryptionRow.options = ["4","5","6"]
           }
        }
    }