inputEx - MenuField Usage

Basic MenuField creation

Use the following code to create a basic inputEx MenuField.

1  var menuItems = [ 
2   { 
3       text:'America'
4       submenu:{ 
5           itemdata:[ 
6                {text:'United States of America',value:'Us'}, 
7                {text:'Canada',value:'Ca'
8            ] 
9        } 
10   }, 
11    { 
12       text:'Europe'
13       submenu:{ 
14           itemdata:[ 
15                { 
16                    text:'Western Europe'
17                    submenu:{ 
18                       itemdata:[ 
19                            {text:'France',value:'Fr'}, 
20                            {text:'United Kingdom',value:'Uk'}, 
21                            {text:'Germany',value:'De'
22                        ] 
23                    } 
24                }, 
25                { 
26                    text:'Eastern Europe'
27                    submenu:{ 
28                       itemdata:[ 
29                            {text:'Poland',value:'Pl'}, 
30                            {text:'Czech Republic',value:'Cz'}, 
31                            {text:'Slovakia',value:'Sk'
32                        ] 
33                    } 
34                } 
35            ] 
36        } 
37   }, 
38   { 
39        text:'Africa'
40       submenu:{ 
41           itemdata:[ 
42                {text:'Senegal',value:'Sn'}, 
43                {text:'Madagascar',value:'Mg'
44            ] 
45        } 
46    } 
47  ]; 
48 
49new inputEx.MenuField({ 
50    parentEl: 'container1'
51    name: 'country'
52    label: 'Your Country:'
53    menuItems: menuItems 
54}); 
view plain | print | ?

Test with more options

Menu triggered on hover, displayed below the text invite, etc.

Log :
1var menuItems2 = [ 
2   { 
3       text:'America'
4       submenu:{ 
5           itemdata:[ 
6                {text:'United States of America',value:'Us'}, 
7                {text:'Canada',value:'Ca'
8            ] 
9        } 
10   }, 
11    { 
12       text:'Europe'
13       submenu:{ 
14           itemdata:[ 
15                { 
16                    text:'Western Europe'
17                    submenu:{ 
18                       itemdata:[ 
19                            {text:'France',value:'Fr'}, 
20                            {text:'United Kingdom',value:'Uk'}, 
21                            {text:'Germany',value:'De'
22                        ] 
23                    } 
24                }, 
25                { 
26                    text:'Eastern Europe'
27                    submenu:{ 
28                       itemdata:[ 
29                            {text:'Poland',value:'Pl'}, 
30                            {text:'Czech Republic',value:'Cz'}, 
31                            {text:'Slovakia',value:'Sk'
32                        ] 
33                    } 
34                } 
35            ] 
36        } 
37   }, 
38   { 
39        text:'Africa'
40       submenu:{ 
41           itemdata:[ 
42                {text:'Senegal',value:'Sn'}, 
43                {text:'Madagascar',value:'Mg'
44            ] 
45        } 
46    } 
47  ]; 
48 
49var div = YAHOO.util.Dom.get('container2'); 
50 
51var f = new inputEx.MenuField({ 
52    parentEl: 'container2'
53    name: 'country'
54    label: 'Your Country:'
55    required: true
56    typeInvite: 'Hover this text to select a country'
57    menuTrigger: 'mouseover'
58    menuPosition: ['tr','br'], 
59    menuItems: menuItems2 
60}); 
61 
62var logDiv = inputEx.cn('div'nullnull"Log :"); 
63div.appendChild(logDiv); 
64f.updatedEvt.subscribe(function(e,params) { 
65    var value = params[0]; 
66    logDiv.innerHTML += "Updated at "+(new Date())+" with value "+value; 
67            logDiv.appendChild(inputEx.cn('br')); 
68}); 
69 
70var button1 = inputEx.cn('button'nullnull"SetValue with 'Fr' (France)"); 
71div.appendChild(button1); 
72YAHOO.util.Event.addListener(button1, "click" ,function() {  
73    f.setValue("Fr");  
74}); 
75var button2 = inputEx.cn('button'nullnull"SetValue with empty string"); 
76div.appendChild(button2); 
77YAHOO.util.Event.addListener(button2, "click" ,function() {  
78    f.setValue(''); 
79}); 
80 
81var button3 = inputEx.cn('button'nullnull"GetValue"); 
82div.appendChild(button3); 
83YAHOO.util.Event.addListener(button3, "click" ,function() {  
84    alert(f.getValue()); 
85}); 
86 
87var button4 = inputEx.cn('button'nullnull"Clear"); 
88div.appendChild(button4); 
89YAHOO.util.Event.addListener(button4, "click" ,function() {  
90    f.clear(); 
91}); 
view plain | print | ?