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

DataFormDataField OnChange?

3 Answers 81 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 13 Oct 2011, 03:52 PM
I noticed that if a DataFormDataField is bound to an integer field, if a non-integer value is entered in the DataFormDataField (like clearing the field), the backend object is not updated.  This causes problems because the UI and the backend object are now out of sync.  I would like to be able to replace non-valid values that are entered in the UI with a valid value (like 0) so that the backend and the UI remain in sync.  I tried handling the TextInput event, but this event does not seem to fire when the DataFormDataField is bound.  How can I best handle invalid data entered in my DataFormDataField?

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 17 Oct 2011, 09:57 AM
Hi Brian,

I have prepared an example project that implements a possible approach to your scenario. Please refer to it and let us know whether this solution meets your requirements.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Brian
Top achievements
Rank 1
answered on 17 Oct 2011, 02:38 PM
Ivan,
This approach seems to work in your example, but when I change the example to be more similar to my project, the event no longer fires.  I can reproduce this problem in your example solution.  Change the RadDataForm XAML in your solution to this:

<telerik:RadDataForm x:Name="radDataForm" AutoGenerateFields="False">
            <telerik:RadDataForm.EditTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <telerik:DataFormDataField Name="ID" DataMemberBinding="{Binding ID, Mode=TwoWay}" Label="ID:" />
                        <telerik:DataFormDataField Name="Name" DataMemberBinding="{Binding Name, Mode=TwoWay}" Label="Name:" />
                    </StackPanel>
                </DataTemplate>
            </telerik:RadDataForm.EditTemplate>
        </telerik:RadDataForm>

When you load the page and click the edit icon, the fields will appear with the values, but if you change the ID field to a non-integer value and tab out of the field, the BindingValidationError no longer appears to fire.  Is there a way to make your approach work in this situation?

Thanks,
Brian
0
Accepted
Ivan Ivanov
Telerik team
answered on 17 Oct 2011, 03:08 PM
Hi Brian,

The solution was designed to work with autogenerated fields. I have used the DataTemplate from you previous post, adapting it to my initial approach. I am attaching the updated version for your reference.

Greetings,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
DataForm
Asked by
Brian
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Brian
Top achievements
Rank 1
Share this question
or