neoneye/SwiftyFORM

Update Readme to explain how to get results

justdan0227 opened this issue · 5 comments

Having fun using this package. However, I don't see an explanation of how you get the results of the form after its filled out? Am I missing something?

In the SignUpViewController there is is a randomizeButton and a jsonButton.

To assign a form field a value, something ala travelPlans.value = "mars"

To read a form field, something ala let plan2024 = travelPlans.value

Suggestions for how this can be explained is much welcome. I'm no native English speaker, so a proposal for a text, is a huge help in preparing a good text.

oh my bad. I thought there was a method to get all of the values in the form as a dictionary. Didn't even think of getting the .value of all of the lazy vars.

How do you go about getting the values of items you built using:

builder += TextFieldFormItem().title("Phone Number: ").placeholder("ex (214) 555-1212").keyboardType(.phonePad)

Can you also explain what validateAndUpdateUI and validate() does? If I have a submit button, can I call one of those to ensure the form is properly filled out and then start retrieving values?

Ok my bad again, now I understand. So on my submit button I do the following:

@IBAction func saveProfileBtnPressed(_ sender: Any) {
        formBuilder.validateAndUpdateUI()
        let result = formBuilder.validate()
        
        switch result {
        case .valid:
            simpleAlert(title: "VALIDATED", msg: "OK READY TO SUBMIT")
            print (fname.value)
            print (lname.value)
            print (displayName.value)
            print (phoneNumber.value)
            
        case .invalid:
            break
        }
}

You got it 👍