neoneye/SwiftyFORM

Is it possible to change form dynamically depends from user choice?

andrewSvsg opened this issue · 4 comments

For example user switch On/Off some option and and new section with some content will occur/hide in the current table

There is no way to do this, yet. However it can be implemented fairly easy.

First modify the FormBuilder class with the desired functions.

Next modify the FormViewController class and perhaps other classes.

Need this too so working on solution

so I tried to add: (removing a form item if segment 0 is selected in a segmentedControl

public func removeInnerItem(_ item: FormItem) {
        if let found = innerItems.firstIndex(where: {$0.elementIdentifier == item.elementIdentifier}) {
            innerItems.remove(at: found)
        }
            
    }

and added a elementIdentifier. However I can't get the form to reload like it would with tableview.reloadData()

instance.valueDidChangeBlock = {[weak self] (value: Int) in
            print (value)
            if value == 0 {
                self?.mainBuilder.removeInnerItem(self!.venueListFormItem)
                self?.mainBuilder.validateAndUpdateUI()
            }
        }

The form cannot insert/remove fields dynamically. I can't recall why I said it was easy to make. I think nowadays it's non-trivial to code.