DataFormDataField OnChange?

4 posts, 2 answers
  1. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 13 Oct 2011 Link to this post

    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?
  2. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 17 Oct 2011 Link to this post

    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 >>
  3. DevCraft banner
  4. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 17 Oct 2011 Link to this post

    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
  5. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 17 Oct 2011 Link to this post

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