PDA

View Full Version : how to set a certain store value in multiselect



bugsbunny
14 Jul 2009, 5:24 PM
Hi I have a multiselect which has a remote store.I want set a predefined value for it..

This was working till ver 3.0 rc1.1 however once i have installed 3.0.0.I get an error saying

this.view is undefined at line number 243 in multiselect.js

setValue: function(values) {
var index;
var selections = [];
this.view.clearSelections(); // it fire bug says this.view is undefined.
this.hiddenField.dom.value = '';

if (!values || (values == '')) { return; }

if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
for (var i=0; i<values.length; i++) {
index = this.view.store.indexOf(this.view.store.query(this.valueField,
new RegExp('^' + values[i] + '$', "i")).itemAt(0));
selections.push(index);
}
this.view.select(selections);
this.hiddenField.dom.value = this.getValue();
this.validate();
},



so when should I set the value..I mean which event.. Rite now I load it when store load event...

any help on this please...


Thanks

bkgrover
11 Aug 2009, 6:57 AM
I'm getting the same error when the setValue() method is called in the multiselect.js file off of the initial loading of the page.

Here is my code for the multiselect:



{
xtype: 'multiselect',
fieldLabel: 'Products <br /><i>Press ctr and click</i>',
name: 'Products__c',
width: 250,
height: 110,
allowBlank:false,
store: [['Angel', 'Angel'], ['Opportunity', 'Opportunity'], ['RIA', 'RIA'], ['Venture Capital', 'Venture Capital']],
tbar:[
{
text: 'Clear selection...',
handler: function(){
company.getForm().findField('Products__c').reset();
}
},
{
text:"test",
handler:function(){
company.getForm().findField("Products__c").setValue("Angel,Opportunity");
}
}
]
//,ddReorder: true
},
And here is my json data that is returned to load the form...



{success:true,data:{"Id":"","Name":"Test Company No. 2","Entity_Class__c":"Deal / Investment Company","Executive_Summary__c":"test exect for test 2","Mission_Statement__c":"test mission for company 2","Commitment_Term_In_Months__c":"12.0","Description_of_Opportunity__c":"test description for company no 2","Final_Close_Date__c":"2009-11-10","Fund_Raising_Target__c":"1000000.0","Maximum_Commitment_Amount__c":"20000.0","Opportunity_Open_Date__c":"2009-07-10","Return_Percentage__c":"15.0","Website__c":"www.test.com","Business_Origination_Date__c":"2009-06-10","Number_of_Employees__c":"13.0","Incorporation_State__c":"TX","Industry__c":"Technology","Opportunity_Status__c":"Open","Products__c":"Angel,Opportunity","Risk_Level__c":"Medium","Strategy__c":"Energy and Power,Infrastructure","Type_of_Business__c":"Private","Type_of_Investment__c":"Distressed Situation,Growth Capital","Associated_Company__c":"a1D40000000CbbgEAC","Primary_Contact__c":"0034000000YOy3GAAT","Mailing_Address_1__c":"123 Two Ln","Mailing_Address_2__c":"Suite 200","Mailing_City__c":"Dallas","Mailing_State__c":"TX","Mailing_Zip__c":"75889","Mailing_Country__c":"US","Shipping_Address_1__c":"321 Two Ln","Shipping_Address_2__c":"Suite 2","Shipping_City__c":"Dallas","Shipping_State__c":"TX","Shipping_Zip__c":"75889","Shipping_Country__c":"US"}}
I put a test button in to see if I could run setValue() after the control was rendered and it works fine for setting the selected items. So, the problem has to be that the multiselect control is not completely rendered or something because "this.view" is undefined.

How can I make sure that the view in the Multiselect.js is set before the setValue function is called?

bugsbunny
17 Aug 2009, 9:13 PM
IS your multiselect in a fieldset and is collapsed by default..If so then the form cannot fied the fields and then the problem occurs. I created a work around for this.. I first keep the fieldset expanded and the form load sets the values and i then hode it..


HOpe this helps

Bugsbunny

bkgrover
18 Aug 2009, 3:37 AM
Yes, my multiselect is in a fieldset but it was not collapsed by default. I tried many different options and found that the problem was not related to the multiselect but rather I was creating tabs in a tabpanel and I wasn't using unique ids / names for them so the parent formpanel / tab object was not defined (correctly).

Once I correct this problem then I was able to use the mulitselect.Although, I ended up using the Ext.ux.form.LovCombo which worked perfectly and actually looks and functions better in my opinion than the xtype:'multiselect'.