var dataPerson = {}; //Variable global para almacenar los datos del formulario
/*
* Funcion para agregar los datos a la variable global y a la lista.
*/
function addContact(event){
event.preventDefault();
event.stopPropagation();
var form = event.data.form; //recibe el Objeto $("form") desde la variable del evento
var dataForm = form.serializeArray(); //Guardamos todos los inputs
var liHtml = ""; //html de la lista vacio
var indice = "";
var datosActuales = {};
$.each(dataForm, function(){ //iteramos los datos de cada input
if(this.name == "inName") {
/* Si el el campo de nombre lo almacenamos pues sera nuestro indice de busqueda */
indice = this.value;
/* Generamos un elemento de la lista el cual tendra como ID el nombre
esto nos servirá para ubicarlo después
*/
liHtml += "<li id=\"" + this.value + "\" class=\"show-details\"><span>" + this.value + "</span></li>";
}
datosActuales[this.name] = this.value;
});
dataPerson[indice] = datosActuales; //Almacenamos los datos en la variable global
$("#dataPersons").append(liHtml); //anexamos el elemento a la lista
form[0].reset(); //restablecer formulario
}
/*
* Función para quitar el elemento <li class="details"> que no se este utilizando
*/
function destroyDetail(){
$(".details").remove();
}
/*
* Funcion para mostrar los datos en detalle que estan almacenados en la variable global
* para realizarlo utilizamos el nombre ya que fue nuestro indice en addContact()
*/
function showDetail(event){
event.stopPropagation();
destroyDetail();
var currentLi = $(event.currentTarget);
var id = currentLi.attr("id");
var dataHtml = "<span>" + dataPerson[id].inName + "</span>"
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.