Search code examples
swiftxcodeeureka-forms

Eureka- Hiding row depending on ActionSheetRow value


I am trying to hide a row based on the value chosen in the ActionSheetRow before it .If the user picks they live in a cold climate I would like to hide or keep hidden the ActionSheetRow of where they would prefer to swim.

 func testForm(){
        form +++ Section("Test")
            <<< TextRow("Your Name"){
                $0.placeholder = "Enter Your Name"
        }
            <<< ActionSheetRow<String>("placeOfLiving") {
                $0.title = "Continent"
                $0.selectorTitle = "Where do you live?"
                $0.options = ["Antartica","Australia","Africa", "Asia", "Europe", "North America", "South America"]

        }
            <<< ActionSheetRow<String>("swimming") {
                $0.hidden = Condition.function([])
                { form in
                    if let section = form.rowBy(tag: "placeOfLiving") as? ActionSheetRow<String> {
                        if section.value == "Antartica" {
                            return true
                        }
                    }
                    return false
                }
                $0.title = "Swimming"
                $0.selectorTitle = "Where do you like to swim?"
                $0.options = ["Pool","Beach","Lake", "River"]

        }

    }

How would I go about checking the value of the ActionSheetRow and then hiding the following row? I have attempted different ways on how to do this check but cannot find a similar scenario. Any feedback welcomed


Solution

  • You need to pass the tag of the rows that you want to check for values inside hidden function array as below.

    $0.hidden = Condition.function(["rowTag"])
    

    So, your code will become,

    $0.hidden = Condition.function(["placeOfLiving"])
       { form in
          if let row = form.rowBy(tag: "placeOfLiving") as? ActionSheetRow<String> {
              return section.value == "Antartica"
           }
           return false
       }