Updating the value of another item from didCommitProperty

Thread is closed for posting
2 posts, 1 answers
  1. Sal
    Sal avatar
    58 posts
    Member since:
    Feb 2015

    Posted 02 Dec 2015 Link to this post

    I have two questions, both relate to using Pickers in the editor. First, is there a way to find out if a Picker is "open" and if so change the editorValueLabel. So for an example in the Calendar App if you tap on a Date and the DatePicker opens up the text on the field that's being changed changes to a red color. The second issue is that is there a way to update the value of another field based on what was committed by the Picker? I have added the didCommitProperty method and I can see when one date is updated, but what I would want to do is that if that date is set to something further ahead of the second date then the second date needs to be updated as well (basically I have a start and end time for a meeting and need to make sure the times selected work for the server). Here's an example of what I got but the dataForm doesn't update to show the new time even though it looks like it's being saved correctly. 


    override func dataForm(dataForm: TKDataForm, didCommitProperty property: TKEntityProperty) {
            //when the start date is changed make sure it's before the end date
            if property.name == "startDate" {
                //get the new start date that was saved
                let newStart = self.editableEvent.startDate
                let currentEnd = self.editableEvent.endDate
                //check if the start date is before the end date
                if newStart.compare(currentEnd) == .OrderedDescending {
                    //the end date needs to be updated to 30 minutes after the new start date
                    let newEndDate = newStart.getXMinutesFromDate(minutes: 30)
                    self.editableEvent.endDate = newEndDate

  2. Answer
    Adrian avatar
    174 posts

    Posted 04 Dec 2015 Link to this post

    Hi, Sal, 

    Thank you for contacting us.

    1. You can handle the selection of the editor by adoption TKDataFormDelegate and implement the didSelectEditor:forProperty: method where you can change the text color of the value label. Please consider the code sipped below:
    func dataForm(dataForm: TKDataForm, didSelectEditor editor: TKDataFormEditor, forProperty property: TKEntityProperty) {
        if property.name == "startDate" {
            let datePicker = editor as! TKDataFormDatePickerEditor
            datePicker.editorValueLabel.textColor = UIColor.redColor()

    2. TKDataForm works through TKEntityProperty to change the properties values of your business object and to update its editors. So to achieve what you described you should change the valueCandidate of the TKEntityProperty that corresponds to the property of your business object instead of the object itself. The code snippet below is an example how this can be achieved:
    func dataForm(dataForm: TKDataForm, didCommitProperty property: TKEntityProperty) {
        if property.name == "startDate" {
            let startDate = property.originalValue as! NSDate
            let endDate = NSDate(timeInterval: 60*60*24*3, sinceDate: startDate)
            let endDateProperty = dataSource["endDate"]
            endDateProperty.valueCandidate = endDate

    I hope this helps. I will be happy to assist in case you have more questions.

    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