Prevent submit on return and fire an Update command

4 posts, 0 answers
  1. hjd
    hjd avatar
    6 posts
    Member since:
    Jul 2014

    Posted 22 Sep 2015 Link to this post

    I have a RadGrid, on which I enabled the Edit mode. When I hit the edit icon a column from the grid can be edited (see the attached Grid2.png). At this point I want to edit the text and confirm with ENTER. On hitting ENTER I want to prevent the form submission and fire the grid update command. Unfortunately the submission prevention doesn't work, the grid update command is fired. Here is what I tried:

     function OnGridKeyPressed(sender, eventArgs) {
        if (eventArgs.get_keyCode() === 13) {
            Cancel​Submission(eventArgs);
            var mtv = $find(sender.ClientID).get_masterTableView();
            var items = mtv.get_editItems();
            if (items.length == 1) {
                var idx = items[0].get_itemIndexHierarchical();
                mtv.fireCommand('Update', idx);
            }
        }
    }

    function CancelSubmission(args) {
        args.set_cancel(true);
        return false;
    }

    Also this in Cancel​Submission: 

    function Cancel​Submission() {
        var e = window.event;
        e.cancelBubble = true;
        e.returnValue = false;
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
    }

    Any help will be appreciated!

     

    Thanks in advance

    Vasil

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 25 Sep 2015 Link to this post

    Hello,

    Note that the commands like Edit, Update, Cancel etc grid commands make an implicit call to the Rebind() method of RadGrid in order to refresh the control's content and fetch the latest information from the grid source. Take a look at this article to more about Commands that invoke Rebind() implicitly.
    You may try to disable the ViewState. As mentioned in the documentation, when RadGrid's ViewState is turned off, the NeedDataSource event does not fire after any of the commands.

    Regards,
    Maria Ilieva
    Telerik
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. hjd
    hjd avatar
    6 posts
    Member since:
    Jul 2014

    Posted 07 Oct 2015 Link to this post

    Hello Maria,

    First of all, thank you for your reply and sorry for taking me so long to answer. I think you didn't understand me correct. My problem is not the execution of the Rebind() method, but the form submission on hitting RETURN. The problem ocurs mainly in Mozilla Firefox, because in my method Cancel​Submission() window.event resp. e is undefined and I cannot cancel the form submission.

    Anyway, I managed to resolve my problem. After digging a while I saw the method get_domEvent() in your eventArgs object. Passing this domEvent to the CancelSubmission() method did the trick. Here is my working code:

     

    function OnGridKeyPressed(sender, eventArgs) {
        if (eventArgs.get_keyCode() === 13) {
            Cancel​Submission(eventArgs.get_domEvent());
            var mtv = $find(sender.ClientID).get_masterTableView();
            var items = mtv.get_editItems();
            if (items.length == 1) {
                var idx = items[0].get_itemIndexHierarchical();
                mtv.fireCommand('Update', idx);
            }
        }
    }

     

    function Cancel​Submission(domEvent) {
        // prevent misbehaviour in Firefox
    var e = null;     
    if (window.event) {         
    e = window.event;     
    }
    else {
    e = domEvent;
    }
    e.cancelBubble = true;
    e.returnValue = false;
    if (e.stopPropagation) {
    e.stopPropagation();
    e.preventDefault();
    }
    }

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 12 Oct 2015 Link to this post

    Hi,

    I'm glad that you were able to fix the issue on your end. Do not hesitate to contact us back in case further assistance is needed.

    Regards,
    Maria Ilieva
    Telerik
    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