Title: Combobox and data-options URL problem
Post by: MFS on December 30, 2015, 12:14:29 AM
Hello there. Im starting to use easyUI and its great. I have two questions about combobox. This is part of my code in dialog:
1. <div class="fitem"> <label>Tip odsustva:</label> <input id="cc" class="easyui-combobox" name="TipOdsustva" data-options="valueField:'ID',textField:'Naziv',url:'LookTipOdsustva.php'" required="true" > </div>
This code is ok and work what I need. But question is, how to set url to different location.This file LookTipOdsustva.php is now in root of project and work fine. When I create subfolder on root with name Test and put file LookTipOdsustva.php there, my combobox dosnt work.Sample after I change folder: url:'Test/LookTipOdsustva.php
Why?
2. When I click to edit some row in my data grid, its open dialog.Like on picture 1.png. (http://s4.postimg.org/egp7kt2fh/image.png) All fields is populated.Works great. BUT, if I change something, date or note and try to save, I recive error.After I do full check with sql profiler, I notice that combobox try to post text from combobox, not VALUE that I need. If after opening in edit mode, I againg select value in combobox than is all ok.Combobox post value, not text, and than is ok. This is problem, if user want to change other values, but not value in combobox or if on dialog more combobox, then he need to reselect all again. How to fix it?
Thanks.
Title: Re: Combobox and data-options URL problem
Post by: stworthy on December 30, 2015, 08:22:00 PM
How do you define your form and the 'combobox' component? How do you fill data to the form? Please show some code snippets or an example to describe it.
Title: Re: Combobox and data-options URL problem
Post by: MFS on December 31, 2015, 12:02:50 AM
This is my code. First one is datagrid and dialog: <table id="ZZOGrid" title="" class="easyui-datagrid" style="auto;height:600px" url="ZahtjevZaOdsustvoGET.php" toolbar="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" > <thead> <tr> <th field="Broj" width="20">Broj</th> <th field="STATUS" width="70">Status</th> <th field="TipOdsustvaSifra" width="15">Šifra</th> <th field="TipOdsustva" width="70">Tip odsustva</th> <th field="PlaniraniPocetak" width="50">Planirani početak</th> <th field="PlaniraniKraj" width="50">Planirani kraj</th> <th field="Obrazlozenje" width="150">Obrazloženje</th> <th field="RealiZOvanoRadnihDana" width="50">Broj realizovanih dana</th> <th field="Odluka" width="100">Odluka voditelja</th> </tr> </thead> </table> <!-- SKUnos --> <div id="toolbar"> <a id="btnNovi" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="ZZOUnos()">Novi</a> <a id="btnAzuriranje" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="ZZOIzmjena()">Izmjeni</a> <a id="btnBrisanje" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="ZZOBrisanje()">Obriši</a> </div> <!-- Forma za unos --> <div id="windowZZOForma" class="easyui-dialog" style="width:400px;height:350px;padding:10px 20px" closed="true" buttons="#dlg-buttons"> <div class="ftitle"></div> <form id="frmZZOUnos" method="post" novalidate> <div class="fitem"> <label>Tip odsustva:</label> <input id="cc" class="easyui-combobox" name="TipOdsustva" data-options="valueField:'ID',textField:'Naziv',url:'LookTipOdsustva.php'" required="true" > </div> <div class="fitem"> <label>Planirani početak:</label> <input id="PlaniraniPocetak" name="PlaniraniPocetak" class="easyui-datebox" required="true"> </div> <div class="fitem"> <label>Planirani kraj:</label> <input id="PlaniraniKraj" name="PlaniraniKraj" class="easyui-datebox" required="true"> </div> <div class="fitem"> <label>Obrazloženje</label> <input name="Obrazlozenje" class="easyui-textbox" data-options="multiline:true" style="height:60px;"> </div> </form> </div> <div id="dlg-buttons"> <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="ZZOCuvanje()" style="width:90px">Sačuvaj</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#windowZZOForma').dialog('close')" style="width:90px">Odustani</a> </div>
This is line for combobox: <div class="fitem"> <label>Tip odsustva:</label> <input id="cc" class="easyui-combobox" name="TipOdsustva" data-options="valueField:'ID',textField:'Naziv',url:'LookTipOdsustva.php'" required="true" >
</div> This is code that populate combobox: <?php include 'Konekcija/Konekcija.php'; $query = " SELECT SO.SOdsustvo AS ID, SO.Naziv AS Naziv FROM dbo.SOdsustvo AS SO "; $rs = sqlsrv_query($konekcija, $query); $items = array(); while($row = sqlsrv_fetch_object($rs)) { array_push($items, $row); } echo json_encode($items); sqlsrv_free_stmt( $query);
?>
This is php code that do all works about edit/update: <?php
$Broj = intval($_REQUEST['broj']); $SOdsustvo = htmlspecialchars($_REQUEST['TipOdsustva']); $PlaniraniPocetak = htmlspecialchars($_REQUEST['PlaniraniPocetak']); $PlaniraniKraj = htmlspecialchars($_REQUEST['PlaniraniKraj']); $Obrazlozenje = htmlspecialchars($_REQUEST['Obrazlozenje']);
include 'Konekcija/Konekcija.php';
$CRUD = '2'; $JMBG= $GLOBALS['KorisnikJMBG']; $KorDat= date("Y-m-d H:i:s"); $SKorisnik= $GLOBALS['KOrisnikID'];
$parametri = array( array($CRUD, SQLSRV_PARAM_IN), array($Broj, SQLSRV_PARAM_IN), array($JMBG, SQLSRV_PARAM_IN), array($SOdsustvo, SQLSRV_PARAM_IN), array($PlaniraniPocetak, SQLSRV_PARAM_IN), array($PlaniraniKraj, SQLSRV_PARAM_IN), array($Obrazlozenje, SQLSRV_PARAM_IN), array($SKorisnik, SQLSRV_PARAM_IN), array($KorDat, SQLSRV_PARAM_IN) );
$procedura = "{call dbo.spCRUDZahtjevZaOdsustvo(?,?,?,null,?,?,?,?,?,?)}";
$result = sqlsrv_query( $konekcija, $procedura, $parametri); if ($result){ echo json_encode(array('success'=>true)); } else { echo json_encode(array('errorMsg'=>'Greška pri čuvanju zsapisa.Zapis nije saučvan.')); }
sqlsrv_free_stmt($result); sqlsrv_close($konekcija);
?>
NOTICE: THis code is working for update, but I MUST reselect value in combobox manaly or combobox will try to post text from combobox, not Value that I need. In insert mode, combobox put VAULE, and that is OK. This is insert code, php: <?php
$SOdsustvo = htmlspecialchars($_REQUEST['TipOdsustva']); $PlaniraniPocetak = htmlspecialchars($_REQUEST['PlaniraniPocetak']); $PlaniraniKraj = htmlspecialchars($_REQUEST['PlaniraniKraj']); $Obrazlozenje = htmlspecialchars($_REQUEST['Obrazlozenje']);
include 'Konekcija/Konekcija.php';
/*------------------------- DODJELJUJEMO VRJEDNOSTI -----------------------*/
$CRUD = '1'; $JMBG= $GLOBALS['KorisnikJMBG']; $Datum = date("Y-m-d H:i:s"); $SKorisnik= $GLOBALS['KOrisnikID']; $KorDat= date("Y-m-d H:i:s");
$parametri = array( array($CRUD, SQLSRV_PARAM_IN), array($JMBG, SQLSRV_PARAM_IN), array($Datum, SQLSRV_PARAM_IN), array($SOdsustvo, SQLSRV_PARAM_IN), array($PlaniraniPocetak, SQLSRV_PARAM_IN), array($PlaniraniKraj, SQLSRV_PARAM_IN), array($Obrazlozenje, SQLSRV_PARAM_IN), array($SKorisnik, SQLSRV_PARAM_IN), array($KorDat, SQLSRV_PARAM_IN) );
$procedura = "{call dbo.spCRUDZahtjevZaOdsustvo(?,null,?,?,?,?,?,?,?,?)}"; $result = sqlsrv_query( $konekcija, $procedura, $parametri);
$Greska = 'Nije moguće izvršiti unos.';
if ($result){ echo json_encode(array('success'=>true)); } else { echo json_encode(array('errorMsg'=>$Greska)); } sqlsrv_free_stmt($result); sqlsrv_close($konekcija);
?>
Any idea? Also, did anybody have idea for my first question about url/path of php file for populating combobox...You can see question in my first post on top of this topic. Thanks.
Title: Re: Combobox and data-options URL problem
Post by: stworthy on December 31, 2015, 12:33:27 AM
Your combobox is defined as: <input id="cc" class="easyui-combobox" name="TipOdsustva" data-options="valueField:'ID',textField:'Naziv',url:'LookTipOdsustva.php'" required="true" >
The data loaded into combobox should be: [{ID:1, Naziv:'Naziv1'},{ID:2, Naziv:'Naziv2'},{ID:1, Naziv:'Naziv3'}] Here is the column in your datagrid. <th field="TipOdsustva" width="70">Tip odsustva</th> When open the dialog and load form data, you may call: $('#frmZZOUnos').form('load', row); When calling this 'load' statement, the row['TipOdsustva'] value will be set to the combobox component. This value must match the 'ID' value in the combobox list. Here is the correct data bound on datagrid. [{TipOdsustva:1, ...},{TipOdsustva:2,...}] Please check the json data returned from 'ZahtjevZaOdsustvoGET.php'. If the 'TipOdsustva' field has a wrong value, please correct it.
Title: Re: Combobox and data-options URL problem
Post by: MFS on December 31, 2015, 12:43:45 AM
This js function is do all stuff about update / edit. function ZZOIzmjena(){ var row = $('#ZZOGrid').datagrid('getSelected'); if (row){ $('#windowZZOForma').dialog('open').dialog('setTitle','Izmjena'); $('#frmZZOUnos').form('load',row); url = 'azuriranje.php?broj='+row.Broj; } }
If I this line: <th field="TipOdsustva" width="70">Tip odsustva</th> change to this: <th field="Sifra" width="70">Tip odsustva</th> update is working fine without reloading combobox, but than is in combobox is ID ( numbers, Sifra is caption for ID ).I need text. How to pass that problem?
Title: Re: Combobox and data-options URL problem
Post by: MFS on December 31, 2015, 04:56:13 AM
JS response is: [{"TipOdsustva":1,"Naziv":"godisnji odmor"},{"TipOdsustva":2,"Naziv":"bolovanje"},{"TipOdsustva":3,"Naziv" :"placeno odsustvo"},{"TipOdsustva":4,"Naziv":"neplaceno odsustvo"},{"TipOdsustva":5,"Naziv":"porodiljsko" },{"TipOdsustva":6,"Naziv":"stari godisnji odmor"},{"TipOdsustva":7,"Naziv":"n\/a"},{"TipOdsustva":10 ,"Naziv":"bolovanje dugo"},{"TipOdsustva":11,"Naziv":"bolovanje trudnicko"},{"TipOdsustva":12,"Naziv" :"Povreda na radu preko 30 dana"},{"TipOdsustva":13,"Naziv":"bolovanje-maligna oboljenja"},{"TipOdsustva" :14,"Naziv":"trudnicko Brcko Distrikt"}]
SQL profiler: exec dbo.spCRUDZahtjevZaOdsustvo '2',18083,'1410986100021',NULL,'Povreda na radu preko 30 dana','12/08/2015','12/11/2015','Novi unos, testy','141','2015-12-31 12:55:42'
Still trying to insert ,'Povreda na radu preko 30 dana', instead of ID...This is only when I try to do edit/update.If I reselect manualy this value then is ok.
Title: Re: Combobox and data-options URL problem
Post by: MFS on January 18, 2016, 05:28:25 AM
Is there any idea for solution?
|