EasyUI Forum
October 24, 2025, 03:53:02 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox and data-options URL problem  (Read 18952 times)
MFS
Newbie
*
Posts: 47



View Profile
« 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.

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.
« Last Edit: December 30, 2015, 12:16:18 AM by MFS » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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.
Logged
MFS
Newbie
*
Posts: 47



View Profile
« Reply #2 on: December 31, 2015, 12:02:50 AM »

This is my code.
First one is datagrid and dialog:
Code:
<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:
Code:
<?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:

Code:
<?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'];
$KorDatdate("Y-m-d H:i:s");
$SKorisnik$GLOBALS['KOrisnikID'];


$parametri = array( 
                 array(
$CRUDSQLSRV_PARAM_IN),
 array($BrojSQLSRV_PARAM_IN),
 array($JMBGSQLSRV_PARAM_IN),
 array($SOdsustvoSQLSRV_PARAM_IN),
 array($PlaniraniPocetakSQLSRV_PARAM_IN),
 array($PlaniraniKrajSQLSRV_PARAM_IN),
 array($ObrazlozenjeSQLSRV_PARAM_IN),
 array($SKorisnikSQLSRV_PARAM_IN),
 array($KorDatSQLSRV_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&#353;ka pri &#269;uvanju zsapisa.Zapis nije sau&#269;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:

Code:
<?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'];
$KorDatdate("Y-m-d H:i:s");

$parametri = array( 
                 array(
$CRUDSQLSRV_PARAM_IN),
 array($JMBGSQLSRV_PARAM_IN),
 array($DatumSQLSRV_PARAM_IN),
 array($SOdsustvoSQLSRV_PARAM_IN),
 array($PlaniraniPocetakSQLSRV_PARAM_IN),
 array($PlaniraniKrajSQLSRV_PARAM_IN),
 array($ObrazlozenjeSQLSRV_PARAM_IN),
 array($SKorisnikSQLSRV_PARAM_IN),
 array($KorDatSQLSRV_PARAM_IN)
               );

$procedura "{call dbo.spCRUDZahtjevZaOdsustvo(?,null,?,?,?,?,?,?,?,?)}";
$result sqlsrv_query$konekcija$procedura$parametri);


$Greska 'Nije mogu&#263;e izvr&#353;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.
« Last Edit: December 31, 2015, 12:08:11 AM by MFS » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: December 31, 2015, 12:33:27 AM »

Your combobox is defined as:
Code:
<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.


Logged
MFS
Newbie
*
Posts: 47



View Profile
« Reply #4 on: December 31, 2015, 12:43:45 AM »

This js function is do all stuff about update / edit.
Code:
		
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?
Logged
MFS
Newbie
*
Posts: 47



View Profile
« Reply #5 on: December 31, 2015, 04:56:13 AM »

JS response is:
Code:
[{"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:

Code:
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.
Logged
MFS
Newbie
*
Posts: 47



View Profile
« Reply #6 on: January 18, 2016, 05:28:25 AM »

Is there any idea for solution?
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!