Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Eureka Hide Section On Change

I am using the Eureka Swift form library found here.

I have a textfield and whenever you start typing in it, I would like the other sections of the form to be hidden. I started out by just trying to hide 1 section but nothing happens when I start typing in the field. My code is as follows:

  form  +++ Section("Device Search")

        <<< IntRow()
            {
                $0.title = "Asset Tag"
                $0.placeholder = "Enter Asset Tag #"
            }

            .onChange { row in

              self.form.sectionBy(tag: "iOS Version")?.hidden = true
        }

        +++ Section("iOS Version")


        for version in countArray
        {

            form.last! <<< CheckRow()
                {
                    $0.title = version
                    $0.tag = $0.title


            }
        }

Also, is there a way to use an IntRow but remove the formatter for just the row?

like image 297
Martheli Avatar asked Jan 30 '23 17:01

Martheli


1 Answers

About your second question is there a way to use an IntRow but remove the formatter for just the row?

Add this line $0.formatter = nil just below this one $0.placeholder = "Enter Asset Tag #"

Your first question, how hide a section in EurekaForm, first of all your section initialisation is not what you think it is, I will explain myself, you think that you are initalizating your section with tag, but in section definition none of init methods use tag as parameter so to get the correct section you need change your section initialization for this one

        +++ Section("iOS Version"){ //"iOS Version" is actually the header text"
            $0.tag = "test"  //this is the tag
        }

after that you need to modify this

.onChange { row in

              self.form.sectionBy(tag: "iOS Version")?.hidden = true
        }

by this one

 .onChange { row in
                if let section = self.form.sectionBy(tag: "test")
                {
                    section.hidden = true 
                    section.evaluateHidden()   //you are missing calling this method
                }
        }

After that your header named "iOS Version" is hidden after you write any number on your IntRow

Full Code

form  +++ Section("Device Search")
            
            <<< IntRow()
                {
                    $0.title = "Asset Tag"
                    $0.placeholder = "Enter Asset Tag #"
                    $0.formatter = nil
                }
                
                .onChange { row in
                    if let section = self.form.sectionBy(tag: "test")
                    {
                        section.hidden = true
                        section.evaluateHidden()
                    }
            }
            
            +++ Section("iOS Version"){
                $0.tag = "test"
        }
        
        for version in countArray
        {
            form.last! <<< CheckRow()
                {
                    $0.title = version
                    $0.tag = $0.title
            }
        }
like image 148
Reinier Melian Avatar answered Feb 04 '23 03:02

Reinier Melian