espace Posted December 26, 2018 Share Posted December 26, 2018 Hi, I have made this jsfiddle : https://jsfiddle.net/espace3d/1dz5yhot/ What i want is add a new item when i press the enter key (see addItem function ). But i can't access to the item with w2ui.js. Wich variable must i use for that in my addItem function ? Thanks for your assist. <!DOCTYPE html> <html> <head> <title>W2UI Demo: fields-3</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script type="text/javascript" src="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.js"></script> <link rel="stylesheet" type="text/css" href="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.css" /> </head> <body> <div style="height: 10px"></div> <div class="w2ui-field w2ui-span3"> <label>Combo:</label> <div> <input type="combo"> <span class="legend">You can type any text</span> </div> </div> <div style="height: 20px"></div> <style> .w2ui-field input { width: 200px; } .w3ui-field > div > span { margin-left: 20px; } </style> <script type="text/javascript"> var data={ description:["georges","henry"], } var addItem=function(item){ data.description.push(item) data.description.sort(); } $('input[type=combo]').w2field('combo', { items: data.description, }); $( 'input[type=combo]' ).keypress(function(event) { if(event.key == 'Enter'){ console.log( "Handler for .keypress() called." ); ///////////////////////////////////////// //WHAT I WANT TO DO //addItem(something) } }); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
espace Posted December 26, 2018 Author Share Posted December 26, 2018 I forgot to specify i use w2ui.js. here is the doc about the combo : http://w2ui.com/web/docs/1.5/form/fields-list Quote Link to comment Share on other sites More sharing options...
espace Posted December 27, 2018 Author Share Posted December 27, 2018 Nobody ? Quote Link to comment Share on other sites More sharing options...
Milton Posted December 27, 2018 Share Posted December 27, 2018 You would need to alter the source. Combo doesn't do what you want. Quote Link to comment Share on other sites More sharing options...
espace Posted December 27, 2018 Author Share Posted December 27, 2018 Sorry but i don't understand. It 's not possible with combo ? Quote Link to comment Share on other sites More sharing options...
Milton Posted December 27, 2018 Share Posted December 27, 2018 No Either change the w2 source or maybe try jQuery Combo. I'm sure they have a combo with add item. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.