* zin: add remove rows and add rows function of thinktableinput.

This commit is contained in:
Zhangyu
2024-05-20 09:03:27 +00:00
parent 14b32c2ac3
commit 5f43031a8d
+42
View File
@@ -12,3 +12,45 @@ window.changeInput = function(e)
const intValue = value < 1 ? 1 : parseInt(value, 10);
$(this).val(intValue);
}
/**
* Set line number.
*
* @access public
* @return void
*/
function setLineIndex()
{
let index = 0;
$('.rows-group').each(function()
{
$(this).find('[name^="addFileds"]').attr('name', 'addFileds[' + index + ']');
$(this).find('[name^="result"]').attr('name', 'result[' + index + ']');
index ++;
});
$('.add-rows').toggleClass('disabled', index >= canAddRows);
}
window.addRow = function(e)
{
if($('.rows-template').hasClass('hidden'))
{
$('.rows-template').removeClass('hidden');
}
else
{
if($('.rows-group').length >= canAddRows) return;
var parentFormGroup = $(e.target || e).closest('.form-group');
var $newRow = $('.rows-template').clone();
$newRow.find('.btn-add').attr('onclick', 'addRow(this)');
$newRow.removeClass('rows-template');
$newRow.find('textarea').val('');
parentFormGroup.after($newRow);
}
setLineIndex();
}
$(document).on('click', '.btn-delete', function() {
var $row = $(this).closest('.form-group');
$row.remove();
setLineIndex();
})