3 ms·
Ask HN: jQuery Key/Value Pair Input Plugin
Is there a jQuery widget like 'tagsinput' (http://xoxco.com/projects/code/tagsinput/) built for inputting key/value pairs? Basically two input text boxes, with the option to add additional rows of key/value pairs?
- haydenchambers 15y agodon't know of any existing plugin.. but you could just write it fairly simply, the following only responds to return key on the two inputs.. var kv_store; //shouldn’t really be global $('document').ready(function() { kv_store = []; $('#kv_key, #kv_value').keyup(function(e) { if(e.keyCode == 13) { //return key hit do yo thing var k = $('#kv_key').val(), v = $('#kv_value').val(), already_stored = false; //check if store already $.each(kv_store, function(index, item) { if(item.k == k) { already_stored = true; kv_store[index].v = v; } }); if(!already_stored) { //if not already in store push it in kv_store.push({k:k,v:v}); } //reset inputs $('#kv_key').val(''); $('#kv_value').val(''); console.log(kv_store); } }); });