Code:
Ext.Loader.setConfig({
enabled: true,
paths: {
'Ext.ux': '../extjs/examples/ux/'
}
});
Ext.require('Ext.ux.form.MultiSelect');
Ext.define('MyApp.view.MyForm', {
extend: 'Ext.form.Panel',
height: 250,
width: 400,
layout: {
align: 'stretch',
type: 'vbox'
},
bodyPadding: 10,
fieldDefaults: {
labelAlign: 'top',
labelPad: 10,
labelStyle: 'font-weight:bold',
afterLabelTextTpl: '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'textfield',
anchor: '100%',
fieldLabel: 'Group Name',
allowBlank: false,
value: 'NewGroup',
name: 'NewGroupTextfield',
},
{
xtype: 'multiselect',
store: Ext.create('Ext.data.ArrayStore', { fields: ['field'] }),
msgTarget: 'side',
fieldLabel: 'Select nodes for group',
flex: 1,
allowBlank: false,
name: 'NewGroupMultiselect',
id: 'NewGroupMultiselect',
itemId: 'NewGroupMultiselect',
// value: Ext.StoreMgr.lookup('MyStore').first(),
},
{
xtype: 'displayfield',
id: 'NewGroupDisplayField',
itemId: 'NewGroupDisplayField',
fieldLabel: 'Nodes selected',
value: 1,
},
],
buttons: [
{
text: 'Cancel',
handler: function() {
this.up('form').getForm().reset();
this.up('window').hide();
}
},
{
text: 'Create',
handler: function() {
var myForm = this.up('form').getForm(),
values;
if (myForm.isValid()) {
// In a real application, this would submit the form to the configured url
// this.up('form').getForm().submit();
myForm.reset();
this.up('window').hide();
values = myForm.getValues();
Ext.MessageBox.alert('Form is valid with the following values: <br/>' + values);
}
else {
Ext.MessageBox.alert('Form is invalid.');
}
}
},
],
});
me.callParent(arguments);
}
});
Ext.onReady(function(){
function launchPanel() {
var win;
win = Ext.widget('window', {
title: 'New Group',
closeAction: 'hide',
width: 400,
height: 400,
layout: 'fit',
resizable: true,
modal: true,
items: Ext.create('MyApp.view.MyForm')
});
win.show();
}
var mainPanel = Ext.widget('panel', {
renderTo: Ext.getBody(),
title: 'MultiSelect Test',
width: 500,
bodyPadding: 20,
items: [{
xtype: 'component',
html: 'Click the button to launch the panel.',
style: 'margin-bottom: 20px;'
}, {
xtype: 'container',
style: 'text-align:center',
items: [{
xtype: 'button',
cls: 'contactBtn',
scale: 'large',
text: 'Launch Panel',
handler: launchPanel
}]
}]
});
});