PDA

View Full Version : How to sync combobox and textfield value



psdhabekar
19 Oct 2012, 3:13 AM
I am new to EXTjs.I was struggling with this issue and at last decided to ask for help.My question is " How to sync combobox and textfield values. i.e how to load different values from 'store' on textfield,while I am changing values on combobox? " My problem is that while I load values on combobox and I select them my textfield stays empty all the time.For this i am using CODEIGNITER .I successfully loaded combox values but unable to get respective value in textbox.I am getting respective value in CONTROLLER of codeigniter but i am not getting it in VIEW of codeigniter.I want combobox and textfield to be synched with store somehow. Any help is appreciated.



My view code:
var getResID = new Ext.data.JsonStore({
url: BASE_URL + 'DisplayResourceListForTransaction',
root:'rows',
fields:['ProdID', 'Name'],
baseParams: {projectid: '<?php $projectID = $this->uri->segment(4); echo $projectID; ?>'}
});



function retriveQty(prID){
Ext.Ajax.request({
url: BASE_URL + 'RetriveQuantity',
method: 'POST',
params: { prID:prID, projectid: '<?php $projectID = $this->uri->segment(4); echo $projectID; ?>'}
});
}
distributeWnd = new Ext.Window({

title:'Distribute',
bodyStyle:'padding:5px',
height: 400,
width: 1000,
layout: 'form',
labelWidth:125,
items: [{
xtype: 'combo',
fieldLabel: 'Resource ID',
width:250,
name: 'resourceID',
id:'resourceID-combo',
store:getResID,
displayField:'Name',
valueField:'ProdID',
editable:false,
mode:'remote',
forceSelection:true,
triggerAction:'all',
emptyText:'Select a resource...',
selectOnFocus:'true',

listeners:
{
select: function(cmb,rec,idx)
{
var prID = cmb.getValue();
var quantity = retriveQty(prID);
Ext.Msg.show({
title: 'Confirm',
msg: 'Delete Selected Users ?'+prID+quantity,
buttons: Ext.Msg.YESNO,
fn: function(btn) {

if (btn == 'yes') {}
}
})
}

}
// anchor:'95%'
// editor:getSuppID

},{
xtype: 'datefield',
fieldLabel: 'Date For Transaction',
disabled: true,
value:new Date(),
format:'d-m-Y',
name: 'Date',
id:'Date'
//
},{
xtype: 'textfield',
fieldLabel: 'Original Qty',
name: 'Qty',
disabled: true,
id:'Qty',
store:getResID

},{
xtype:'textfield',
fieldLabel:'Remaining Qty',
disabled: true,
// width:200,
name: 'RQty',
id:'RQty'

}]
}).show();


in above code i called getResID and filled combobox but i want to update textfield Qty respective to that selected combo box value for this i called retriveQty on the select of combobox but i am not getting it from controller but in controller it getting here unable to get value from controller to view...
My controller code is:



public function DisplayResourceListForTransaction()
{
$projectID = $_POST['projectid'];

$projectID = "PRO_".$projectID;

$projectDb =& $this->hitdb->connection($projectID);

$qry = "SELECT DISTINCT [ProdID], [Name], [Unit] FROM [ConsumedProductData] ORDER BY [ProdID]";
$res = $projectDb->query($qry);

$arr = array();
foreach ( $res->result() as $obj)
{
$arr[] = $obj;

}
$resCNT = $projectDb->count_all('ConsumedProductData');

echo '{success:true,numrow:'.$res->num_rows().',results:'. $resCNT .
',rows:'.json_encode($arr).'}';
}

public function RetriveQuantity()
{
$resID = $_POST['prID'];

$projectID = $_POST['projectid'];
$projectID = "PRO_".$projectID;
$projectDb =& $this->hitdb->connection($projectID);
$qry = "SELECT [Name] FROM [ConsumedProductData] WHERE [ProdID] = '".$resID."'";
$res = $projectDb->query($qry);
foreach ( $res->result() as $data)
{
$resName= $data->Name;
}

$m = date('m');
$yr = date('Y');
$day = date('d');
// print_r($m."/".$day."/".$yr);
$TrDt = $m."/".$day."/".$yr;

$InQry = "SELECT SUM(Quantity) AS TOTIN FROM [ConsumedProductData] INNER JOIN [ConsumedProduct] ON [ConsumedProduct].[ID] = [ConsumedProductData].[ID] WHERE [ConsumedProduct].[DocumentDate] <= '";
$InQry .= $TrDt . "' AND [ConsumedProductData].[ProdID]='";
$InQry .= $resID . "' AND [ConsumedProductData].[Name] ='" .$resName . "' AND [ConsumedProductData].[StockType] = 1";

$res = $projectDb->query($InQry);
// print_r($InQry);

foreach ( $res->result() as $data)
{
$InQty= $data->TOTIN;
}

$OutQry = "SELECT SUM(Quantity) AS TOTOUT FROM [ConsumedProductData] INNER JOIN [ConsumedProduct] ON [ConsumedProduct].[ID] = [ConsumedProductData].[ID] WHERE [ConsumedProduct].[DocumentDate] <= '";
$OutQry .= $TrDt . "' AND [ConsumedProductData].[ProdID]='";
$OutQry .= $resID . "' AND [ConsumedProductData].[Name] ='" .$resName . "' AND [ConsumedProductData].[StockType] = 2 AND [Quantity] > 0";

$res = $projectDb->query($OutQry);
print_r($OutQry);
foreach ( $res->result() as $data)
{
$OutQty= $data->TOTOUT;
}

$OutQry = "SELECT SUM(Quantity) AS OUT1 FROM [ConsumedProductData] INNER JOIN [ConsumedProduct] ON [ConsumedProduct].[ID] = [ConsumedProductData].[ID] WHERE [ConsumedProduct].[DocumentDate] <= '";
$OutQry .= $TrDt . "' AND [ConsumedProductData].[ProdID]='";
$OutQry .= $resID . "' AND [ConsumedProductData].[Name] ='" .$resName . "' AND [ConsumedProductData].[StockType] = 2 AND [Quantity] < 0 AND ([ConsumedProductData].[Position] IS NULL OR [ConsumedProductData].[Position] = '')";

$res = $projectDb->query($OutQry);
print_r($OutQry);
foreach ( $res->result() as $data)
{
$OutQty1= $data->OUT1;
}

$OutQry = "SELECT SUM(Quantity) AS OUT1 FROM [ConsumedProductData] INNER JOIN [ConsumedProduct] ON [ConsumedProduct].[ID] = [ConsumedProductData].[ID] WHERE [ConsumedProduct].[DocumentDate] <= '";
$OutQry .= $TrDt . "' AND [ConsumedProductData].[ProdID]='";
$OutQry .= $resID . "' AND [ConsumedProductData].[Name] ='" .$resName . "' AND [ConsumedProductData].[StockType] = 2 AND [Quantity] < 0 AND ([ConsumedProductData].[Position] IS NOT NULL AND [ConsumedProductData].[Position] <> '')";

$res = $projectDb->query($OutQry);
print_r($OutQry);
foreach ( $res->result() as $data)
{
$OutQty2= $data->OUT1;
}

$OrgQty = $InQty - $OutQty + $OutQty1 - $OutQty2;

// print_r($InQty."aaa".$OutQty."bbb".$OutQty1."cccc".$OutQty2);
// print_r($OrgQty);


$resCNT = $projectDb->count_all('ConsumedProductData');

echo '{success:true,numrow:'.$res->num_rows().',results:'. $resCNT .
',rows:'.json_encode($OrgQty).'}';
}


here value in $OrgQty not getting in view..thats my problem how to get it.....?
Any help is appreciated.

scottmartin
19 Oct 2012, 5:43 AM
Moving thread to Help/Discussion. Plugins forum is for release announcements.

Scott.

willigogs
19 Oct 2012, 6:02 AM
I'm confused by what you're attempting to achieve here :-/

For starters, textfields cannot have stores.

Are you just trying to populate a textfield with the selected combo value?

psdhabekar
21 Oct 2012, 9:18 PM
Thanks for reply......i just want to show that when i select a combobox value then respective value should be shown in textbox box field...how to do this......and while doing this on the click of combobox i am getting value but it is in controller then my question how to get value from controller to view to display in testbox....?plz help me.

willigogs
22 Oct 2012, 2:51 AM
You would just want to do something like the following:

items: [{
xtype: combo,
listeners: {
select: function (combo, record, index) {
Ext.getCmp('Qty').setValue(combo.value)
},
change: function (combo, newValue, oldValue) {
Ext.getCmp('Qty').setValue(newValue)
}
}
}, {
xtype: 'textfield',
id: 'Qty',
fieldLabel: 'Original Qty',
name: 'Qty',
disabled: true
}]

I added the change event also in case a user selects a combo value without using the mouse.

psdhabekar
22 Oct 2012, 4:28 AM
You would just want to do something like the following:

items: [{
xtype: combo,
listeners: {
select: function (combo, record, index) {
Ext.getCmp('Qty').setValue(combo.value)
},
change: function (combo, newValue, oldValue) {
Ext.getCmp('Qty').setValue(newValue)
}
}
}, {
xtype: 'textfield',
id: 'Qty',
fieldLabel: 'Original Qty',
name: 'Qty',
disabled: true
}]

I added the change event also in case a user selects a combo value without using the mouse.


ya it ok but how to fetch data from json reader...i unable to collect data from jsonreader....here is what i have tried....



function retriveQty(prID){
quantity = new Ext.data.Store({
reader: new Ext.data.JsonReader({

root: 'rows', totalProperty: 'results'
},
[{name:'Quantity', type: 'int' , mapping:'Quantity'}]),
proxy: new Ext.data.HttpProxy({
url: BASE_URL + 'hitdailyinward/main/RetriveQuantity',
method: 'POST'
}),
baseParams: {
prID:prID,
projectid: '<?php $projectID = $this->uri->segment(4); echo $projectID; ?>'
}
});


here i am calling this function on the click of combobox so passed prID from this i called retriveQty function which is in controller i.e


public function RetriveQuantity()
{
...//i calculated quantity
echo '{success:true,numrow:'.$res->num_rows().',results:'. $resCNT .
',rows:'.json_encode($x).'}';//in this way i am returning it but i am not getting in //view......
}




help me plz...

willigogs
22 Oct 2012, 4:51 AM
I'm afraid I don't understand what you're trying to achieve, so not sure I can offer much more help...

psdhabekar
22 Oct 2012, 5:20 AM
I'm afraid I don't understand what you're trying to achieve, so not sure I can offer much more help...

here is what i want to do....

comboBox click--->selection of prID from comboBox---->goes to controller and fetches result from database which we want to show this fetched value in textbox (till this it is working fine) here we are getting this value from controller using jsonReader---->now reader contains data which i want---->How to get value of this reader in some variable??? And then assign to textbox??

willigogs
22 Oct 2012, 5:48 AM
It doesn't really sound like you need a store at all then?

On combo change > Ajax call to the required URL passing the combo value > response returns the value you wish to place in the textfield > In the success handler use .setValue() to set the value of the textfield.

The alternative method would be to cut out the call on combo change altogether, and already have these values returned to you in the original store which the combo uses...

psdhabekar
23 Oct 2012, 1:07 AM
It doesn't really sound like you need a store at all then?

On combo change > Ajax call to the required URL passing the combo value > response returns the value you wish to place in the textfield > In the success handler use .setValue() to set the value of the textfield.

The alternative method would be to cut out the call on combo change altogether, and already have these values returned to you in the original store which the combo uses...
can you plz explain with code.....?

willigogs
23 Oct 2012, 5:38 AM
If I'm understanding your requirements correctly, it would work something like this:



function getAndSetQty(comboValue) {
Ext.Ajax.request({
url: your_url,
params: {
'comboValue': comboValue
},
method:'POST',
success: function(action, response) {
// Assuming response would be something like:
// {"success":true, "quantity": "Some_Returned_Value"}
var json = Ext.decode(action.responseText);
var quantity = json.quantity;
Ext.getCmp('Qty').setValue(quantity);
},
failure: function(action, response) {
console.log('Something Went Wrong')
}
});
}




items: [{
xtype: combo,
listeners: {
select: function (combo, record, index) {
getAndSetQty(combo.value)
},
change: function (combo, newValue, oldValue) {
getAndSetQty(newValue)
}
}
}, {
xtype: 'textfield',
id: 'Qty',
fieldLabel: 'Original Qty',
name: 'Qty',
disabled: true
}]

psdhabekar
25 Oct 2012, 2:01 AM
If I'm understanding your requirements correctly, it would work something like this:



function getAndSetQty(comboValue) {
Ext.Ajax.request({
url: your_url,
params: {
'comboValue': comboValue
},
method:'POST',
success: function(action, response) {
// Assuming response would be something like:
// {"success":true, "quantity": "Some_Returned_Value"}
var json = Ext.decode(action.responseText);
var quantity = json.quantity;
Ext.getCmp('Qty').setValue(quantity);
},
failure: function(action, response) {
console.log('Something Went Wrong')
}
});
}




items: [{
xtype: combo,
listeners: {
select: function (combo, record, index) {
getAndSetQty(combo.value)
},
change: function (combo, newValue, oldValue) {
getAndSetQty(newValue)
}
}
}, {
xtype: 'textfield',
id: 'Qty',
fieldLabel: 'Original Qty',
name: 'Qty',
disabled: true
}]


It worked :) Thanks a lot!

willigogs
25 Oct 2012, 2:42 AM
Glad you got it working :)