xmartlabs / Eureka

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

The image of the minus button does not disappear in MultivaluedSection for MultivaluedOptions = [.Insert] #2229

Closed Nikitaxub closed 2 years ago

Nikitaxub commented 2 years ago

Hi Eureka Team! I want to limit the number of lines by one at minimum.

override func viewDidLoad() {
        super.viewDidLoad()
        form
        +++ MultivaluedSection(multivaluedOptions: [.Insert, .Delete],
                               header: "test") { section in
            section.tag = "testTag"
            section.addButtonProvider = { _ in
                return ButtonRow(){
                    $0.title = "Add row"
                }
            }
            section.multivaluedRowToInsertAt = { index in
                if index > 0 {
                    section.multivaluedOptions = [.Insert, .Delete]
                }
                return NameRow() {
                    $0.value = "\(index + 1) row"
                }
            }
            section <<< NameRow() {
                $0.value = "1 default row"
            }
            section <<< NameRow() {
                $0.value = "2 default row"
            }
        }
        tableView.isEditing = true
    }

    override func rowsHaveBeenRemoved(_ rows: [BaseRow], at indexes: [IndexPath]) {
        super.rowsHaveBeenRemoved(rows, at: indexes)
        let bedtimesSection = form.sectionBy(tag: "testTag") as! MultivaluedSection
        if bedtimesSection.count == 2 {
            bedtimesSection.multivaluedOptions = [.Insert]
        }
    }

This is my code entirely. And it works. In the sense that the last row cannot be deleted 😉 But the image of the minus does not disappear, although touching/clicking does not cause the "delete" button.

image
mats-claassen commented 2 years ago

You need to reload that section, or at least that first row so that the new settings has effect. For example:

    override func rowsHaveBeenRemoved(_ rows: [BaseRow], at indexes: [IndexPath]) {
        super.rowsHaveBeenRemoved(rows, at: indexes)
        let bedtimesSection = form.sectionBy(tag: "testTag") as! MultivaluedSection
        if bedtimesSection.count == 2 {
            bedtimesSection.multivaluedOptions = [.Insert]
            bedtimesSection.reload() // <---
        }
    }
Nikitaxub commented 2 years ago

It works. Thank's.