NewItemTemplate Commit event

8 posts, 0 answers
  1. peter
    peter avatar
    37 posts
    Member since:
    Feb 2011

    Posted 21 Nov 2011 Link to this post

    I have a form which has two templates the edittemplate and the newitemtemplate. I also have the "Ok" button displaying. My problem is that this "OK" button seems to be wired up to the EditEnded event, how can i wire it up to the AddedNewItem event when the newitemtemplate is the template being displayed?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 22 Nov 2011 Link to this post

    Hi Peter,

    Generally, the 'Ok' button executes commit edit command. Would you clarify what is the exact scenario that you want to achieve when inserting new item ? Do you want to execute similar command once a new item is about to be added or when its fields are updated and it is inserted in the data source collection ? 
      

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. peter
    peter avatar
    37 posts
    Member since:
    Feb 2011

    Posted 22 Nov 2011 Link to this post

    Hi Maya,

    I was hoping that when the edittemplate is displayed the "OK" button would trigger the editended event, and when the newitemtemplate is displayed the "OK" button would trigger the AddedNewItem event due to the fact I need to add new data to the database.

    To give some context, i have wired the events to trigger some mvvm commands and at the moment both situations trigger the editended.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 23 Nov 2011 Link to this post

    Hello Peter,

    This would be the expected behavior since in both cases (when editing an item and when adding a new one) the edit is ended and the corresponding event is fired. Actually, there is not AddedNewItem event supported by RadDataForm, only AddingNewItem is available for the time being. 
    What I could suggest is to work with the EditEnded event and verify whether the current item is a new one just inserted in the collection or not. 
    What is the data source collection you are working with ? 
     

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 17 Jul 2013 Link to this post

    And how would one go about determining if the current item was just added to the ObservableCollection? And I'm using MVVM with WCF RIA services just to complicate things. Here's my current code which only handles changes to existing items:

    <telerik:RadDataForm x:Name="locationDetail"
                            ItemsSource="{Binding Locations}"
                            CurrentItem="{Binding SelectedLocation, Mode=TwoWay}"
                            Grid.Column="1"
                            Grid.Row="1"
                            AutoGenerateFields="False"
                            EditTemplate="{StaticResource LocationEditItem}"
                            NewItemTemplate="{StaticResource LocationEditItem}"
                            ReadOnlyTemplate="{StaticResource LocationReadItem}"
                            Margin="-1,0,0,0"
                            CommandButtonsVisibility="Add, Edit, Navigation, Commit, Cancel">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="EditEnded">
                <ei:CallMethodAction TargetObject="{Binding}"
                                        MethodName="SaveLocation"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </telerik:RadDataForm>

    public void SaveLocation()
    {
        if (RepositoryFactory.Instance.Service.HasChanges == false)
        {
            return;
        }
        RepositoryFactory.Instance.Service.SubmitChanges(this.SubmitOperationCompleted, null);
    }

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Jul 2013 Link to this post

    Hello Peter,

    Actually, I discovered a mistake in my answer - there is AddedNewItem event that is thrown right after AddingNewItem event. If you want to check whether committing an edit is performed on the new item, you can try to perform a check similar to:

    private void dataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
            {
                if (this.dataForm.Mode == Telerik.Windows.Controls.Data.DataForm.RadDataFormMode.AddNew && e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
                {
                }
            }

    Will that work for you ?  

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 18 Jul 2013 Link to this post

    How would you do that in a ViewModel and not code-behind? A ViewModel should have no knowledge of the view so this.dataForm.Mode is invalid.
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Jul 2013 Link to this post

    Hello Peter,

    If your collection is IEditableCollectionView for example, you will have all the information required. Check out this article for a reference. 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
DevCraft banner