Search code examples
swiftcallbackeureka-forms

Eureka - DateRow load date without changing its current value


This is my eureka daterow code. Where row value is set only after making any changes in the datepickerview. I need to load the date to row on cell selection on the daterow. Thanks in advance.

enter image description here

form +++ DateRow(name)  {
        $0.title = label
}.onChange({ (row) in
    if let value = row.value {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let date = dateFormatter.string(from: value)

        let item = CustomField(coulmnId: fieldId, columnValue: date)
        self.addToCustom(set: item)
    }
})

Solution

  • You just need to set the row value so that picker can use that at startup,

    form +++ DateRow("name")  {
                $0.title = "label"
            }.onCellSelection({ (cell, row) in
                if row.value == nil {
                    row.value = Date()// Set default value.
                }
            }).onChange({ (row) in
            ...