$(document).ready(function() {
// REMOVE BUTTON
$(document).on("click", ".row-action .remove", function() {
$(this).closest(".data-item").remove();
});
// ADD BUTTON
$(".form-table-wrapper .add").click(function() {
let dataSet = $(this).attr("data-set");
let dataRowClone = $('table[data-set="' + dataSet + '"] tbody tr:last').clone();
$(dataRowClone).find('input.form-input').val('');
$('table[data-set="' + dataSet + '"] tbody').append(dataRowClone);
});
//SAVE BUTTON
$(".form-table-wrapper .save").click(function() {
// SELECT THE RELATED DATA SET
let dataSet = $(this).attr("data-set");
let dataSetRows = $('table[data-set="' + dataSet + '"] .data-item');
let dataSetArray = [];
// FOR EACH ROW IN THE DATA TABLE
$(dataSetRows).each(function(i) {
let dataRow = $(this);
let dataRowInputs = $(this).find(".form-input");
let dataRowArray = [];
// FOR EACH INPUT IN THE ROW
$(dataRowInputs).each(function() {
let inputValue = $(this)[0]["value"];
let className = $(this)[0]["className"].replace("form-input ", "");
let dataItem = {
key: className,
value: inputValue
};
dataRowArray.push(dataItem);
});
dataSetArray.push(dataRowArray);
});
// NEED TO SEND THIS DATA TO THE PS API
console.log(dataSetArray);
});
});
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.