espace

how to access the value in a combo ?

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>

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.