0

I like to change the Type field drop down option depending on the inputs of Year and Level fields.

enter image description here

I am able to trigger an event when Level is change. But how do I get the value of the Year field?

Portion of the code are as follows

    colModel:[
    {name:'Year',index:'Year', width:70,sortable:false,editable:true,align:'center',editoptions:{size:15, maxlength:4}, formoptions:{ rowpos:1, label: "Year (*)"},editrules:{required:true}},
    {name:'Level',index:'Level', width:70,sortable:false,editable:true,align:'center',edittype: "select", editoptions: { value: '1:1;2:2;3:3;4:4;5:5;6:6', defaultValue:'1',  dataEvents : [
        {
            'type' : 'change',
            'fn' : function ( el ) {
                // get the newly selected value from the user
                var levelz = $(el.target).val(), yearz ;
                var row = $(el.target).closest('tr.jqgrow');
                var rowid = row.attr('id');

                //yearz = ??
                if (parseInt(levelz)==5 || parseInt(levelz)==6)
                {
                    if (parseInt(yearz)>2017)
                    {
                        $("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '1:Sem 1;4:Sem 2;6:EY;9:OVR', defaultValue:'Sem 1'}} );
                    }else{
                        $("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '', defaultValue:''}} );
                    }                       
                }else{
                    $("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '1:TA1/CT1;2:TA2-before 2013;3:MY/TA2/CT2;4:TA3/CT3;5:TA4-before 2013;6:EY/TA4/CT4;9:OVR;D:CW1;E:CW2;F:CW3;G:CW4', defaultValue:'TA1'}} );
                }
            }
        }]}, formoptions:{ rowpos:2, label: "Level (*)"},editrules:{required:true}},
    {name:'Term',index:'Term', width:70, sortable:false,editable: true,align:'center',edittype: "select", editoptions: { value: '1:TA1/CT1;2:TA2-before 2013;3:MY/TA2/CT2;4:TA3/CT3;5:TA4-before 2013;6:EY/TA4/CT4;9:OVR;D:CW1;E:CW2;F:CW3;G:CW4', defaultValue:'TA1'}, editrules: { required: true }, formoptions:{ rowpos:3, label: "Type"}},     

The codes are from piecing together what I read from google search... I face 2 issues: 1) I don't know how to get the Year value 2) The drop down option list doesn't seems to change. - hmm it seems that if I close the edit form and open again, the Type field drop down option changes. What I need is to change the option on the fly - wonder how this can be done...

Meng Hai
  • 127
  • 1
  • 14

1 Answers1

1

After much googling, managed to get the ans from Oleg's post as shown here

Also from his example, I derive the year value: var yearz = $("#Year.FormElement", form[0]).val();

Meng Hai
  • 127
  • 1
  • 14