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

3 posts, 0 answers
  1. James
    James avatar
    14 posts
    Member since:
    Jan 2012

    Posted 28 Oct Link to this post

    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. James
    James avatar
    14 posts
    Member since:
    Jan 2012

    Posted 30 Oct in reply to James Link to this post

    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.

  3. DevCraft banner
  4. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 02 Nov Link to this post

    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
Back to Top