0


In the edit Form is a select dropdown. When the user select an item, i want to load some values and fill them into the form.

My code so far:

var grid = $("#list").jqGrid({
  parameters...,
  colNames:[...],
  colModel :[
    ...
  ]
});  

$("#list").jqGrid(
  'navGrid',
  '#pager',
  {
    view:true,
    edit:true,
    del:true,
    search:false,
  },

  /* EDIT */
  {
    closeAfterEdit: true,
    afterSubmit: processAddEdit,
    onInitializeForm: setFormEvents,
    ...
  }
  ...
);


function setFormEvents(formid) {
  /* It sometim works when using timeout..
   * It seems to be a timing issue.
   * But i have no idea why and how to solve
   */
  setTimeout ( function(){
    $('select#data_id', formid).unbind();
    $('select#data_id', formid).change(function() {
      $.getJSON("/URL?dataid=" + $('select#data_id option:selected').val(),
        function(data){
          $.each(data, function(i,item){
            if (item.field == "anrede") { $("#anrede").val(item.value); }
            else if (item.field == "titel") { $("#titel").val(item.value); }
            else if (item.field == "vorname") { $("#vorname").val(item.value); }
            else if (item.field == "nachname") { $("#nachname").val(item.value); }
            else if (item.field == "firma") { $("#firma").val(item.value); }
            else if (item.field == "strasse") { $("#strasse").val(item.value); }
            else if (item.field == "hausnummer") { $("#hausnummer").val(item.value); }
            else if (item.field == "plz") { $("#plz").val(item.value); }
            else if (item.field == "ort") { $("#ort").val(item.value); }
            else if (item.field == "land") { $("#land").val(item.value); }
          });
        });
    });
  }, 1000 );
}
Stahlkocher
  • 219
  • 4
  • 10

1 Answers1

1

To bind event (like change event in your case) to the edit field you should use dataEvents of the editoptions. See here, here or here examples. Moreover I recommend you to use recreateForm:true option additionally.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798