This is a migrated thread and some comments may be shown as answers.

How can I retrieve values entered into form to store in core data

2 Answers 42 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James
Top achievements
Rank 1
James asked on 28 Oct 2016, 01:40 PM

Hi Gurus,

Here is my source 

 

 

import UIKit


class NewUserInfoFormController: TKDataFormViewController {

    let dataSource = TKDataFormEntityDataSource()
    let physicianInfo = UserInfoModel()

    let btn = UIButton()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        self.dataForm.backgroundColor = UIColor(red: 0.937, green: 0.937, blue: 0.960, alpha: 1.0)
        dataSource.sourceObject = physicianInfo


        dataSource["name"].hintText = "Please Enter Full Name"
        dataSource["street"].hintText = "Street"
        dataSource["city"].hintText = "City"
        dataSource["state"].valuesProvider = GeoStates.state
        //dataSource["state"].editorClass = TKDataFormOptionsEditor.self
        dataSource["zip"].hintText = "Zip"
        dataSource["phone"].hintText = "Phone"
        dataSource["phone"].editorClass = TKDataFormPhoneEditor.self
        dataSource["email"].hintText = "Email"
        dataSource["email"].editorClass = TKDataFormEmailEditor.self

        self.dataForm.dataSource = dataSource
        self.dataForm.frame = CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height - 66)
        self.dataForm.tintColor = UIColor(red: 0.780, green: 0.2, blue: 0.223, alpha: 1.0)

        btn.frame = CGRect(x: 0, y: self.dataForm.frame.size.height, width: self.view.bounds.size.width, height: 66)
        btn.setTitle("Cancel reservation", for: UIControlState())
        btn.setTitleColor(UIColor(red: 0.780, green: 0.2, blue: 0.223, alpha: 1.0), for: UIControlState())
        btn.addTarget(self, action: #selector(NewPhysicianFormController.processSubmit), for: .touchUpInside)
        self.view.addSubview(btn)


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    override func dataForm(_ dataForm: TKDataForm, didCommit property: TKEntityProperty) {
        if (property.name == "state'")
        {

        }

    }

    override func dataForm(_ dataForm: TKDataForm, update editor: TKDataFormEditor, for property: TKEntityProperty) {
        //let feedbackDef = editor.gridLayout.definitionForView(editor.feedbackLabel)
        //editor.gridLayout.setHeight(0, forRow: feedbackDef.row.integerValue)

        if property.name == "state" {

        }



        if editor.isKind(of: TKDataFormTextFieldEditor.self) && property.name != "password" {
            property.hintText = "Required"
        }
    }


    func processSubmit() {
        let alert = TKAlert()

        alert.style.cornerRadius = 3;
        alert.title = "Cancel Reservation";
        alert.message = "Reservation Canceled!";


        alert.addAction(withTitle: "OK") { (alert: TKAlert, action: TKAlertAction) -> Bool in

            return true
        }

        alert.show(true)
    }
}

 

How can I get the data stored in various fields in my processSubmit function. I want to be able to store those values in Core Data.

Thanks for your help

 

 

2 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 30 Oct 2016, 10:46 AM

Nevermind. Here is the answer.

 

let nameEditor = self.dataSource["name"]
        let name = nameEditor?.valueCandidate as! String

 

Can this be added to the documentation as I imagine this would be a common scenario.

0
Adrian
Telerik team
answered on 02 Nov 2016, 10:38 AM
Hi, James,

Thank you for the feedback, it is valuable for us. I am logging this and we will update our documentation.

Regards,
Adrian
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataForm
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Adrian
Telerik team
Share this question
or