Search code examples
swiftswift4eureka-forms

how to update a row.value based on another row.value


I'm using a Eureka form, in which the user selects dates. When the user selects the first date, I want to update the second date in the second row (add 30 days to the first days).

        <<< DateRow(){
            $0.value = Date()
            $0.title = "First Date"
            $0.tag = "firstDate"
            .onChange({ (row) in
                << update secondDate = firstDate + 30 days >>
            } )

         <<< DateRow(){
            $0.value = Date()
            $0.title = "Second Date"
            $0.tag = "secondDate"

How can I achieve that?


Solution

  • Please find below solution.

    func createSection() {
        let section = Section("Section2") { section in
            section.header?.height = { 40 }
        }
    
        <<< DateRow() {
            $0.value = Date()
            $0.title = "First Date"
            $0.tag = "First"
            }.onChange({ (row) in
                let secondRow = self.form.rowBy(tag: "Second") as! DateRow
                let date = row.value!
                let newDate = date.addingTimeInterval(30*24*60*60)
                secondRow.value = newDate
                secondRow.reload()
            })
    
        <<< DateRow() {
            $0.value = Date()
            $0.title = "Second Date"
            $0.tag = "Second"
            }.onChange({ (row) in
    
            })
    
        form +++ section
    }
    

    Let me know in case of any queries.