xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

Update a row based on the values in another two rows #2107

Closed reenaphilip closed 4 years ago

reenaphilip commented 4 years ago

I have two DateRow and a LabelRow. Based on the dates selected, I should update the date difference and update the LabelRow value.

    <<< DateRow("FromDateRow"){
            $0.title = "Period From"
            $0.value = Date()//formatter.string(from: Date())
            $0.minimumDate = Date()
        }.onChange({ (row) in
            self.updateNoOfDaysRow()
        })
        <<< DateRow("ToDateRow"){
               $0.title = "Period To"
                $0.value = Date()//formatter.string(from: Date())
                $0.minimumDate = Date()
        }.onChange({ (row) in
            self.updateNoOfDaysRow()
        })
        <<< LabelRow("LeaveCountRow"){
            $0.title = "Total Days"
         self.updateNoOfDaysRow()
        }

The code to update Label :

     func updateNoOfDaysRow(){
    guard let fromRow = self.form.rowBy(tag: "FromDateRow") as? DateRow else{
        return
    }
    let fromDate = fromRow.value
    guard let toRow = self.form.rowBy(tag: "ToDateRow") as? DateRow else{
        return
    }
    let toDate = toRow.value

    guard let countRow = self.form.rowBy(tag: "LeaveCountRow") as? LabelRow else{
        return
    }

    countRow.value = String(describing: self.calculateNumberOfDays(fromDate: fromDate!, toDate: toDate!))
}

But the value is. not updating to the label. Do I need to reload the entire form? Please suggest.

mats-claassen commented 4 years ago

Try running countRow.updateCell() after updating its value.

BTW you should use weak self in all those callbacks

reenaphilip commented 4 years ago

Thank you. its working with updateCell().

Yes I will change to weak self.