0

I am currently working on jqGrid add / edit form. I am implementing custom buttons on both add and edit. with one of the custom buttons I have implemented javascript to post the form to server and reload the grid. This is currently working fine however, the form does not clear of the data that was entered.

i.e I'll like to know how to clear off fields the add form after submitting?

see code below:

beforeShowForm: function () {
    $('<a href="#">Save and New<span class="ui-icon ui-icon-disk"></span></a>')
        .click(function () {
            $.post('<c:url value="/programmes/create"/>',
                $('#FrmGrid_list2').serialize(),
                function (data) {
                    $('#list2').trigger("reloadGrid");
                });
        }).addClass("fm-button ui-state-default ui-corner-all fm-button-icon-left")
          .prependTo("#Act_Buttons>td.EditButton");
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
pundit
  • 772
  • 3
  • 18
  • 31

1 Answers1

1

Probably you forget to use recreateForm: true (see my previous answer). I recommended many times Tony to make the setting default. In any way I recommend you either use always the option or to change defaults in some common JavaScript file which you include on all your pages after jqGrid:

$.extend($.jgrid.edit, { recreateForm: true });
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • recreateForm works great but also reloads the entire page thus loses the scroll position. Is there an Ajax alternative without reloading the page? – devXen Jun 25 '14 at 19:06
  • 1
    @Chensformers: Sorry, but `recreateForm: true` don't makes any reloading of the page. The default form editing option `reloadAfterSubmit: true` do this. You can use `$.extend($.jgrid.edit, { recreateForm: true, reloadAfterSubmit: false });` or just `$.extend($.jgrid.edit, { reloadAfterSubmit: false });`. The most problem which try to solve default reloading of the page: wrong sorting or paging after Add/Edit operation. Additional problem is assigning `id` for new added row. If one use `reloadAfterSubmit: false` one should implement `afterSubmit` too in case of Add operation. – Oleg Jun 25 '14 at 19:39