mirror of
https://github.com/sstent/node.git
synced 2026-02-07 13:02:20 +00:00
updated app
This commit is contained in:
@@ -18,28 +18,32 @@ html
|
||||
$('#employees').html(out);
|
||||
});
|
||||
|
||||
$('#btnAdd').click(function() {
|
||||
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
|
||||
$('.btnAdd').click(function() {
|
||||
var classname = $(this).attr("name")
|
||||
var num = $('.' + classname).length; // how many "duplicatable" input fields we currently have
|
||||
var newNum = new Number(num + 1); // the numeric ID of the new input field being added
|
||||
|
||||
|
||||
// create the new element via clone(), and manipulate it's ID using newNum value
|
||||
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
|
||||
|
||||
var newElem = $("."+classname+"#input" + num).clone().attr('id', 'input' + newNum);
|
||||
|
||||
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
|
||||
|
||||
// manipulate the name/id values of the input inside the new element
|
||||
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
|
||||
|
||||
// insert the new element after the last "duplicatable" input field
|
||||
$('#input' + num).after(newElem);
|
||||
$("."+classname+"#input" + num).after(newElem);
|
||||
$("."+classname+"#input" + newNum).css('display', 'block');
|
||||
|
||||
// enable the "remove" button
|
||||
$('#btnDel').prop('disabled',false);
|
||||
$('.btnDel').prop('disabled',false);
|
||||
|
||||
// business rule: you can only add 5 names
|
||||
if (newNum == 12)
|
||||
$('#btnAdd').prop('disabled',true);
|
||||
});
|
||||
|
||||
$('#btnDel').click(function() {
|
||||
$('.btnDel').click(function() {
|
||||
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
|
||||
$('#input' + num).remove(); // remove the last element
|
||||
|
||||
@@ -51,7 +55,7 @@ html
|
||||
$('#btnDel').prop('disabled',true);
|
||||
});
|
||||
|
||||
$('#btnDel').attr('disabled',true);
|
||||
$('.btnDel').attr('disabled',true);
|
||||
|
||||
$('#save').click(function() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user