0

Hi I have this navGrid definition in Add action.

Grid.id >> $("#<%=Me.Id & "_" %>lstPreciosSUD")

{ width: 350, resize: false, closeAfterAdd: false, recreateForm: true,
    clearAfterAdd:false, viewPagerButtons: true, afterComplete: estadoReplicado,
    ,afterSubmit: function(response) { 
                if (response.responseText == "OK") {

                    alert("we are inside");

                    var myInfo = '<div class="ui-state-highlight ui-corner-all">' +
                        '<span class="ui-icon ui-icon-info" ' +
                        'style="float: left; margin-right: .3em;"></span>' +
                        '<span>Registro insertado correctamente!</span></div>',
                    $infoTr,
                    $infoTd;
                    $infoTr = $("#TblGrid" + "<%=Me.Id & "_" %>lstPreciosSUD" + ">tbody>tr.tinfo");
                    $infoTd = $infoTr.children("td.topinfo");
                    $infoTd.html(myInfo);
                    $infoTr.show();

                    setTimeout(function () {
                        $infoTd.children("div")
                            .fadeOut("slow", function () {
                                  $infoTr.hide();
                            });
                    }, 6000);

                        //alert("Registro creado.");
                        return [true,''];
                } 
                else { 
                        return [false, "Error creando precio de suplemento!"];
                } 
            },
    beforeSubmit: function(postdata){ 
        if ((postdata.tpb_importe == "") || (postdata.fini == "") || (postdata.ffin=="")) {
            return[false,"Importe y fechas es obligatorio!"]; 
        } else { return [true,""] }
    }
}}

In the second or date's inputs if are empty this return (return [false,"Importe y fechas es obligatorio!"] ") returns me a red message in the dialog from beforeSubmit like this http://i.imgbox.com/ackwIZvQ.jpg

I have to use closeAfterAdd:false and clearAfterAdd:false in this case, but i want to know and i have think use afterSubmit to show a green (for example) message if its all OK with a little function to do this, but if i use the above afterSubmit function, and its OK, don't show any message like error message, is possible to show any OK message? If there is an error, it shows it in red color I can't see in background how it add the new record, but in the dialog don't show any message.

Thanks.

bombai
  • 927
  • 1
  • 17
  • 27

1 Answers1

2

If I understand you correct you will find an example of such implementation in the answer (see the demo). It shows how to use add your custom text in the same way like the standard error message will be added. In the demo I used errorTextFormat only to simulate the loading. You should move the code which show successful message in afterSubmit.

UPDATED: The code of afterSubmit could look about as (I don't tested the code)

afterSubmit: function (jqXHR) {
    var myInfo = '<div class="ui-state-highlight ui-corner-all">' +
            '<span class="ui-icon ui-icon-info" ' +
            'style="float: left; margin-right: .3em;"></span>' +
            '<span>The row is successfully added</span></div>',
        $infoTr,
        $infoTd;

    if (jqXHR.responseText !== "OK") {
        return [false, jqXHR.responseText];
    }

    $infoTr = $("#TblGrid_" + $.jgrid.jqID(this.id) + ">tbody>tr.tinfo"),
    $infoTd = $infoTr.children("td.topinfo");
    $infoTd.html(myInfo);
    $infoTr.show();

    // hide the info after 3 sec timeout
    setTimeout(function () {
        $infoTd.children("div")
            .fadeOut("slow", function () {
                // Animation complete.
                  $infoTr.hide();
            });
    }, 3000);
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg! I cant see your errorTextFormat code in the answer. Can you help me? I have searched in all answer links page! Thanks again! – bombai Dec 17 '12 at 11:56
  • @bombai: You can open the source code of [the demo](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWithMsgInEditForm.htm). If you would have some problems I could add the part of the code in my answer. – Oleg Dec 17 '12 at 12:03
  • Hi Oleg! I can see the code, but i dont know where and how should be use! I have to put directly on aftersubmit and call it in pager or its not necessary? Thanks again. – bombai Dec 17 '12 at 14:15
  • Hi OLeg! If i put this code in add or edit action without return true can save the new data, and if i put return [true,''] save the data but dont show any message! Have you any idea? I have edited the first post with how I have the code! Thanks – bombai Dec 17 '12 at 15:57
  • @bombai: What returns the server in case of success (I mean `response.responseText`). Which version of jqGrid you use? Do you tried to debug your application or at least insert `alert` calls inside of `afterSubmit`? Do you have link to the demo which is online? – Oleg Dec 18 '12 at 08:49
  • Hi again Oleg! Thanks for your support! My case when is successful is OK, as you can see in the if statement! My jqgrid version is 4.2.0! I have put one alert and in fact, dont enter in aftersubmit function! Do you know why? I use beforeSubmit and BeforeShowForm and it works at same position! I dont have a demo online! Thanks again! – bombai Dec 18 '12 at 14:25
  • Now i have tried to move this code into beforeSubmit and BeforeShowForm function and with one alert enter in each function shows the alert, but the div definition dont work, dont appear! – bombai Dec 18 '12 at 14:32
  • @bombai: `afterSubmit` should work. You wrote about `aftersubmit`. Do you write correctly `afterSubmit` or you use `aftersubmit` which will be wrong? So first of all the callback `afterSubmit` must be called. You can use `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js` and set set breakpoint in [the lines](https://github.com/tonytomov/jqGrid/blob/v4.2.0/js/grid.formedit.js#L657) and verify why `afterSubmit` not called (see code later). Additionally jqGrid 4.2.0 is more as one year old and it don't set `this`. So you have to replace `$.jgrid.jqID(this.id)` from my code to id of the grid – Oleg Dec 18 '12 at 14:46
  • Well now is enter in afterSubmit, I have changed the grid id and dont work, the new div dont pop up inside the add dialog (on top), i cant change the jpgrid version, the project is very huge to change it and then if some features change it, some code couldnt work. I have changed the first post code! Thanks again! – bombai Dec 18 '12 at 15:15
  • @bombai: You are welcome! You should replace `$("#TblGrid_" + "#lstPreciosSUD"` to `$("#TblGrid_" + "lstPreciosSUD"` if the id of the grid is `"lstPreciosSUD"`. – Oleg Dec 18 '12 at 15:22
  • Hi Oleg, i dont know what else try..It dont show! My grid id is `"#<%=Me.Id & "_" %>lstPreciosSUD"` and in the definition of the top info i put `$infoTr = $("#TblGrid" + "<%=Me.Id & "_" %>lstPreciosSUD" + ">tbody>tr.tinfo");` and dont pop up, save the data but dont popup any div! What else can I try? Thanks! – bombai Dec 18 '12 at 15:37
  • @bombai: The character `'#'` is not part of id. Moreover I don't understand why you use **both** `"<%=Me.Id & "_" %>` and `lstPreciosSUD` together. You don't posted more full definition of your grid, but if for example the id of the grid would be `list` you should use `$("#TblGrid_list>tbody>tr.tinfo")`. The combination `"<%=Me.Id & "_" %>lstPreciosSUD"` seams me wrong. – Oleg Dec 18 '12 at 16:23
  • Yes, this was the mistake! I have remove the me.id code and it works! Thanks for your support and patience! One last thing, do you know what icon can i put on it? The example use "ui-icon ui-icon-info", do you know if exists any green confirmation icon of jqgrid that can i use on it? Thanks again! – bombai Dec 19 '12 at 08:06
  • 1
    @bombai: You are welcome! The color of the icon will be get from jQuery UI CSS which you use. So you can either customize the Theme with respect of [ThemeRoller](http://jqueryui.com/themeroller/). Alternatively you can mix get icons from *another* well-known CSS like le-frog which contains green icons. If you would have implementation problem you can ask new question and I will try to help you. – Oleg Dec 19 '12 at 08:50