Jump to content

how to access the value in a combo ?


espace
 Share

Recommended Posts

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>

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...