EasyUI Forum
May 09, 2024, 01:51:08 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Combogrid cannot read property 'idField' of null  (Read 10323 times)
acreonte82
Jr. Member
**
Posts: 85



View Profile
« on: February 21, 2017, 03:00:13 PM »

Hello to all,
i've this combogrid:
Code:
$('#dna_position').combogrid({
panelWidth:750,
url: 'controller/search_stock_position.php',
idField:'warehouse_number',
textField:'warehouse_number',
mode:'remote',
fitColumns:true,
columns:[[
{field:'warehouse_number',title:'Fridge number',width:250},
{field:'type_of_instrument',title:'Fridge',width:250},
{field:'placing',title:'Place',width:250},
]]
});

This combo in used to load data in a form and the form load the data  in this way:
Code:
$('#dati_dna').form('load', data);

The problem is: if i retrive data from server and no data for the combogrid i've this error:
Code:
Uncaught TypeError: Cannot read property 'warehouse_number' of null

So the question is: how i can solve it? there is a pre-check before to prevent this? Thanks for the help
« Last Edit: February 28, 2017, 01:40:55 PM by acreonte82 » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: February 21, 2017, 07:58:28 PM »

How do you declare the <form> and combogrid component. Please show an example to demonstrate your issue.
Logged
acreonte82
Jr. Member
**
Posts: 85



View Profile
« Reply #2 on: February 22, 2017, 01:27:18 AM »

Hi,
thanks for the support!
This is the html code of the form :
Code:

<form id="search_samplePatient">
     <div>
<label>Search the patient using the protocol number and/or sample number and/or the biological sample type<br/><br/>
<input id="cg_ricerca_paziente" style="width:250px" tabindex="10" class="easyui-validatebox" required="true"></input>
</label>
</div>
<div>
<input type="button" name="Send" value="Search" tabindex="20" onclick="javascript: loadDataQtaSample($('#tt_modifica_qta_sample').tabs('getTabIndex',$('#tt_modifica_qta_sample').tabs('getSelected')));" tabindex="20">
</div>
</form>
<div class="easyui-tabs" id="tt_modifica_qta_sample" >
 <!-- many tabs defined here -->
  <div title="DNA" style="padding:10px;" >
<form id="dati_dna"  method="post">
     <table>
         <tr><input type="hidden" name="dati_extra" value="">
             <td>DNA quantity:</td>
             <td><input name="dna_num_vials_volume" type="text"></input></td>
                 </tr>
                  <tr>
                     <td>DNA position:</td>
                     <td><input id="dna_position" name="dna_position" style="width:150px"></input></td>
                  </tr>
          <tr>
         <td>DNA sampling date:</td>
               <td><input name="sampling_date_dna_position" id="sampling_date_dna_position" class="easyui-datebox" type="text"></input></td>
         </tr>
         <tr>
            <td colspan="2">
               <input type="button" name="Send" value="Modify"  onclick="javascript: submitFormQtaSample(this.form);" >
              </td>
            </tr>
       </table>
     </form>
     </div>
</div>

And this is my javascript code to load data in the form:
Code:
<script type="text/javascript" language="javascript">
      function myformatter(date){
           var y = date.getFullYear();
           var m = date.getMonth()+1;
           var d = date.getDate();
           return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
      }
     function getParametersQtaSample(dati_ricerca,id_tab){
return 'controller/type_modifica_qta_campione_biologico.php?tab='+ id_tab +'&dati_ricerca='+ dati_ricerca;
      }
      function loadDataQtaSample(id_tab){
var data='';
var g = $('#cg_ricerca_paziente').combogrid('grid'); // get datagrid object
var r = g.datagrid('getSelected'); // get the selected row
switch(id_tab){
          case 1:
$('#sampling_date_dna_position').datebox({    
    formatter:myformatter,
              parser:myparser
});
       $('#dna_position').combogrid({
     panelWidth:750,
     url: 'controller/search_stock_position.php',
     idField:'warehouse_number',
     textField:'warehouse_number',
     mode:'remote',
     fitColumns:true,
     columns:[[
{field:'warehouse_number',title:'Fridge number',width:250},
{field:'type_of_instrument',title:'Fridge',width:250},
{field:'placing',title:'Place',width:250},
]]
});
data=getParametersQtaSample(r.dati_ricerca,id_tab);
$('#dati_dna').form('load', data);
          break;
          }
       }
    </script>
the  getParametersQtaSample function call a php script that retrive the data after a specific query and return all by json array. The json array has the key value egual the name value defined in the input control  form.

The combogrid is preload when the webpage is loaded, then when i call  $('#dati_dna').form('load', data) the combogrid select the right value defined in the json array.

The problem is when the json array return null value, in the console of Chrome I've this error:
Code:
Uncaught TypeError: Cannot read property 'warehouse_number' of null 

So my question is how i can manage this kind of situation?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: February 22, 2017, 02:20:03 AM »

Please make sure if the 'data' has the correct data before loading into the form.
Code:
data=getParametersQtaSample(r.dati_ricerca,id_tab);
console.log(data);
$('#dati_dna').form('load', data);
Logged
acreonte82
Jr. Member
**
Posts: 85



View Profile
« Reply #4 on: February 22, 2017, 07:48:44 AM »

yes the data array is correct.

if i found in the json array
Code:
 ... "dna_position":null ... 
it  is because i've not value to set in the combogrid

So if i've null value , how i can prevent the error showed in console?
Logged
acreonte82
Jr. Member
**
Posts: 85



View Profile
« Reply #5 on: February 28, 2017, 01:45:07 PM »

I solved changing the result value from json array
I used "" (empty value) instead of null value.

Thanks for all support
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!