After dynamic table creation, I created a jQuery function that allows the user to copy chosen entries' input values into a staging area via buttons. The values are cloned successfully, but after each button click, the parsley validation error message
"This value should be a valid integer."
appears for every input in the table. Why is the validation perceiving an invalid number entered into the input, and how can this error message be avoided?
Also, there is a button that copies a group of inputs to a staging area, and after that click, the parsley validation error message does not appear. Can anyone see why the single copy would generate the validation message and the group copy would not? The only differences I see are that the validation-triggering code: 1) is called when a class member is clicked as opposed to an ID; and 2) uses the .closest(), .children(), and .eq() methods to navigate the table as opposed to using only IDs to reference table elements. Thanks very much in advance!
The dynamic table row creation in a loop after an AJAX call:
var row = $('<tr></tr>');
var idCell = $('<td></td>').append($('<input type="submit" class="btn btn-info contractToOffer" value="Add To Contracts">'));
row.append(idCell);
idCell = $('<td class="text-center" id="contractID' + data[i].ContractID + '"></td>').append(data[i].ContractID);
row.append(idCell);
idCell = $('<td class="text-center"></td>').append(Number(Number(data[i].ContractPrice) + Number(data[i].ContractMargin)).toFixed(2));
row.append(idCell);
idCell = $('<td class="text-center"><input id="contractValue' + data[i].ContractID + '" value="' + Number(Number(data[i].ContractPrice) + Number(data[i].ContractMargin)).toFixed(2) + '" step="0.01" class="contractInput" type="number" name="quantity" min="1" max="50000"></td>').append();
row.append(idCell);
Moving function that generates validation message:
$("#contractPanel").on("click", ".contractToOffer", function () {
var $offerContractOne = $("#OfferContract1"),//In staging area
$offerPriceOne = $(".price1"),//Also in staging area
$movingContract = 0,
$movingPrice = 0.00,
$oCells = $(this).closest('tr').children('td');
$movingContract = $oCells.eq(1).text();
$movingPrice = $("#contractValue" + $movingTerm.toString()).val();
$offerContractOne.val($movingTerm);//Staging area
$offerPriceOne.text($movingPrice);//Also staging area
});
And finally, the group copying that doesn't generate any message via a "standardOffers" button, which I would also like the single-copy code to do:
$("#contractPanel").on("click", "#standardOffers", function () {
var $oContractOne = $("#OfferContract1"),
$oPriceOne = $(".price1"),
$oContractTwo = $("#OfferContract2"),
$oPriceTwo = $(".price2"),
$oContractThree = $("#OfferContract3"),
$oPriceThree = $(".price3"),
$oContractFour = $("#OfferContract4"),
$oPriceFour = $(".price4"),
$oContractFive = $("#OfferContract5"),
$oPriceFive = $(".price5"),
//The preceding are in the staging area
$standardPrice = 0.00
for (var i = 1; i < 6; i = i + 1) {
if ($("#contractID" + i).length > 0) {
$standardPrice = $("#contractValue" + i.toString()).val();
if (i == 1) {
$oContractOne.val(i.toString());
$oPriceOne.text($standardPrice);
}
else if (i == 2) {
$oContractTwo.val(i.toString());
$oPriceTwo.text($standardPrice);
}
else if (i == 3) {
$oContractThree.val(i.toString());
$oPriceThree.text($standardPrice);
}
else if (i == 4) {
$oContractFour.val(i.toString());
$oPriceFour.text($standardPrice);
}
else {
$oContractFive.val(i.toString());
$oPriceFive.text($standardPrice);
}
}
}
});
event.preventDefault()'in the code when handling the button presses for the copy?