PDA

View Full Version : Help ME..passing value into texfield



ivone_tarigan
19 Aug 2010, 7:38 PM
hiii all i wanna pasing value from database into textfield in js..

im using getCmp and set value into textfield..

this is my code to get value from databse


Ext.Ajax.request
({
url:purchase.core.purchase_requisition.controller+'/tes',
params:
{
'pr_number':result1,
},
callback: function(options, success, response)
{
var respon = response.responseText;
console.log('response: '+respon);
Ext.getCmp('pr_number').setValue(respon);
}
});


and this is my form


initComponent: function()
{
Ext.apply(this,{
items: [{
xtype:'fieldset',
layout:'column',
autoHeight:true,

width: 1500,
items:[{

columnWidth:.300,
layout: 'form',
items: [
{
xtype:'textfield',
fieldLabel: 'PR Number',
anchor:'70%',
name: 'pr_number',
id: 'pr_number',
//value:pr_number,
readOnly:true
},



im very confuse..why value doesnt display in my textfield..and when i compile ad given erorr..

response: 00004
Ext.getCmp("pr_number") is undefined
chrome://firebug/content/blank.gif Ext.getCmp('pr_number').setValue(respon);


i hope you can help me...

thanks _ivone_

ivone_tarigan
19 Aug 2010, 8:24 PM
help me guyss....:(

Condor
19 Aug 2010, 10:24 PM
Are you sure your form has been created when you receive the value?

ivone_tarigan
19 Aug 2010, 11:05 PM
yup..thats the point..

im not sure..when i receive thats value..my form hasnot benn created..

but..if receive thats value into other form and the value is displaying...im very confuse about it..

this is my full code..

this is my form :


purchase.core.purchase_requisition.form = Ext.extend(Ext.form.FormPanel,{
constructor: function(config)
{
config = config||{};
config.labelWidth = config.labelWidth || 120;
config.frame = config.frame || true;
config.autoHeight = config.autoHeight || true;
config.title = config.title || 'Purchase Requisition Form';
config.bodyStyle = config.bodyStyle || 'padding:1px 1px 1px';
config.width = config.width || 365;
config.defaults = {width: 200},
config.border = config.border || false;

purchase.core.purchase_requisition.form.superclass.constructor.call(this, config);
},

initComponent: function()
{
Ext.apply(this,{
items: [{
xtype:'fieldset',
layout:'column',
autoHeight:true,

width: 1500,
items:[{

columnWidth:.300,
layout: 'form',
items: [
{
xtype:'textfield',
fieldLabel: 'PR Number',
anchor:'70%',
name: 'pr_number',
id: 'pr_number',
//value:tes,
readOnly:true
},

{
xtype:'textfield',
fieldLabel: 'Order for Delivery to',
anchor:'70%',
name: 'pr_order_for_delivery_to',
id: 'pr_order_for_delivery_to'
}, {
xtype:'textarea',
fieldLabel: 'Purpose Required',
anchor:'70%',
name: 'pr_purposed_required',
id: 'pr_purposed_required'

}, {
xtype:'datefield',
fieldLabel: 'Date required',
name: 'pr_date_required',
id: 'pr_date_required',
anchor:'70%'
},{
xtype:'hidden',
fieldLabel: 'action',
name: 'action',
id: 'action',
value : 'save',
anchor:'80%'
}

]
},
{
columnWidth:.300,
layout: 'form',
items: [{
xtype:'combo',
fieldLabel: 'Branch',
id:'pr_branch',
store: new purchase.core.purchase_requisition.comboStoreBranch(),
name: 'pr_branch',
displayField : 'branch_name',
mode:'remote',
valueField : 'branch_id',
hideTrigger:false,
triggerAction : 'all',
minChars:2,width: 250,
typeAhead : true,
loadingText: 'Please Wait...',
forceSelection : true,
editable: false,
emptyText : 'Select Branch',
selectOnFocus : true,
anchor:'70%',
allowBlank: true,
},
{
xtype:'combo',
fieldLabel: 'Division',
id:'pr_division',
store: new purchase.core.purchase_requisition.comboStoreDivisi(),
name: 'pr_division',
displayField : 'divisi_name',
mode:'remote',
valueField : 'divisi_id',
hideTrigger:false,
triggerAction : 'all',
minChars:2,width: 250,
typeAhead : true,
loadingText: 'Please Wait...',
forceSelection : true,
editable: false,
emptyText : 'Select Divisi',
selectOnFocus : true,
anchor:'70%',
allowBlank: true,
}
,{
xtype:'combo',
fieldLabel: 'Department',
store: new purchase.core.purchase_requisition.comboStoreDepartment(),
id:'pr_department',
name: 'pr_department',
displayField : 'department_name',
mode:'remote',
valueField : 'department_id',
hideTrigger:false,
triggerAction : 'all',
minChars:2,width: 250,
typeAhead : true,
loadingText: 'Please Wait...',
forceSelection : true,
editable: false,
emptyText : 'Select Department',
selectOnFocus : true,
anchor:'70%',
allowBlank: true,
}
,{
xtype:'combo',
fieldLabel: 'Ship Mode',
id:'pr_shipmode',
store: values,
name: 'pr_shipmode',
store: values,
displayField:'value',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select Ship Mode...',
loadingText: 'Please Wait...',
selectOnFocus:true,
anchor:'70%',
allowBlank: true,
}

]
},
]}
],
buttonAlign: 'center',
buttons:[
{
text: 'Save',
iconCls:'icon-disk ',
listeners:
{
click:
{
scope: this,
fn: savePurchaseRequisition
}
}
},
{
text: 'Cancel',
listeners:
{
click:
{
scope:this,
fn: function()
{
this.getForm().reset();
}
}
}
}]

});
function savePurchaseRequisition()
{
if(this.getForm().isValid())
{
Ext.Ajax.request
({
url: purchase.core.purchase_requisition.controller +'/save',
params: this.getForm().getValues(),
callback: function(options, success, response)
{

var respon = response.responseText;
console.log('response: '+respon);

if(respon == '1')
{
Ext.getCmp('pr_grid').getStore().reload();
Ext.MessageBox.alert('Status','Purchase Requisition Has Been Saved..',response.responseText);
}

else
{
Ext.MessageBox.alert('Purchase Requisition Saving Failed..',response.responseText);

}
}
});
}
this.getForm().reset();

}



purchase.core.purchase_requisition.form.superclass.initComponent.apply(this, arguments);
},


getFormValues: function()
{
var retVal = {};
this.items.each(function(item) {
retVal[item.name] = item.getValue();
});
return retVal;
}
});


this is code when i displaying form..

purchase.core.purchase_requisition.sitegridform = Ext.extend(Ext.Panel, {
constructor: function(config){
config = config || {};
config.width = config.width || 900;
config.border = config.border || false;
config.layout = 'form';

purchase.core.purchase_requisition.sitegridform.superclass.constructor.call(this, config);
},
initComponent: function(){
Ext.apply(this, {
items: [
this.form = new purchase.core.purchase_requisition.form({
width: 900,
autoHeight: true
})
]
});

purchase.core.purchase_requisition.sitegridform.superclass.initComponent.apply(this, arguments);
}



and this is my code to get the value and i take it in top..global variable..


Ext.namespace('purchase.core.purchase_requisition');
purchase.core.purchase_requisition.controller = 'index.php/core/purchase_controller';

var result1='';

Ext.Ajax.request
({
url:purchase.core.purchase_requisition.controller+'/tes',
params:
{
'pr_number':result1,
},
callback: function(options, success, response)
{
var respon = response.responseText;
console.log('response: '+respon);
Ext.getCmp('pr_number').setValue(respon);
}
});