Caritatis

Just another WordPress.com weblog

jQgrid change element in form based on another August 12, 2011

Filed under: jQgrid — caritatis @ 4:56 pm

David Hansen, 2009/09/19 15:59

Here’s an example of using editoptions dataEvents to change another form element based on an onChange event in a <select>. In this case, the form contains Job_Name and Job_Number fields. The value of the Job_Number field is set using the value of the selected Job_Name option.

 {  name:   'Job_Number',
    index: '`Job #`',
    editable: true,
    edittype: 'text',
    editoptions: { size: 10, readonly: 'readonly'},
    editrules: {required: true },
    formoptions: { label: 'Job #' },
    width: 10,
    formatter: 'integer',
    formatoptions: { thousandsSeparator: '' },
    searchoptions: { sopt: ['eq','ne','lt','le','gt','ge', 'in', 'ni'] },
    align: 'right',
    sortable: true
 },
 {  name:   'Job_Name',
    index: '`Job Name`',
    editable: true,
    edittype: 'select',
    editoptions: { size: 1,
                   dataUrl: 'Includes/tblJobSelect.php',
                   dataEvents: [
                      {  type: 'change',
                         fn: function(e) {
                            $('input#Job_Number').val(this.value);
                         }
                      }
                   ]
    },
    formoptions: { label: 'Job Name' },
    searchoptions: { sopt: ['eq','ne','lt','le','gt','ge', 'cn', 'nc', 'bw', 'bn'] },
    align: 'right',
    width: 150,
    align: 'left',
    sortable: true
 },

this – in $(‘input#Job_Number’).val(this.value); – refers to the DOM element associated with the onChange event, the Job_Name <select>, in this case.

The dataUrl returns plain text HTML ”<select><option value=999>Some Job Name</option>…</select>” that jqGrid uses to create the select.

Notice the use of the readonly attribute on the Job_Number field.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules

Advertisement
 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.