Извините за данный некорректный вопрос .. здесь я объясняю полную проблему ..
Я использую динамическую таблицу и хочу проверить динамические строки и столбцы.
Но это не такработает.
Пример, если я добавляю две строки и хочу заполнить все поля (столбцы), но, к сожалению, пропустил один столбец, а затем, если я нажму кнопку "Отправить", я не хочу разрешить отправку. Если я нажму кнопку «Отправить», я хочу показать «Заполните все столбцы» следующим образом ..
Примечание. Я не использую FORM в своей таблице.
Проверка динамических строки столбцы
Полный код здесь.
Fiddle
Пример кода здесь.
$(document).ready(function() {
$("#ok_button").on("click", function() {
$("#acc_narrat0").val($("#cash_text:first").val());
});
$("#add_Row").on("click", function() {
var counter = 0;
var idVal = $('#tab_logic tr:last').find('td:first').html();
// alert(idVal);
var matches = idVal.match(/\d+/g);
// alert(matches);
if (matches != null) {
counter = Number(matches) + counter + 1;
}
// alert(counter);
var newRow = $("<tr>");
var cols = "";
cols += '<td class="cashpay_led" style="display:none;"><input type="number" class="form-control" id="table_ledger' + counter + '" name="ledgerno" placeholder="ledger number"/></td>';
cols += '<td><input type="number" class="form-control sel_text accValidate" id="cashAcctcode' + counter + '" name="acctcode" placeholder="Account code"/></td>';
cols += '<td><select class="form-control sel_sel status" id="accountName' + counter + '" name="accountName"><option>Choose A/c Name</option></select></td>'
cols += '<td><input value="' + $("#cash_text:first").val() + '" type="text" class="form-control required price" name="narr" placeholder="Enter your text here" id="acc_narrat' + counter + '" data-toggle="modal" data-target="#narratModal" onchange="unname(this.id, this.value)"/></td>';
cols += '<td><input type="text" class="form-control debitValidate" id="cashdeb' + counter + '" data-action="sumDebit" name="debit" placeholder="Debit amount"/></td>';
cols += '<td><input type="number" class="form-control comment" id="crditCash' + counter + '" data-action="sumCredit" name="credit" placeholder="Credit amount" tabindex="-1" readonly/></td>';
cols += '<td><button type="button" class="adRow ibtnDel" style="width:70%;">x</button></a></td>';
newRow.append(cols);
var defVal = $("select[name=acctname]").find(":selected").val();
if (defVal) {
$("select[name=accountName]").find(`option[value=${defVal}]`).hide();
}
$("table.order-list").append(newRow);
setValCashVal('accountName'.concat(counter));
bindScript();
counter++;
});
// delete function
$("table.order-list").on("click", ".ibtnDel", function(_event) {
$(this).closest("tr").remove();
evaluateTotal();
// counter -= 1
});
});
/* validation */
$(document).ready(function() {
$('#tablogic').on('submit', function(event) {
//Add validation rule for dynamically generated name fields
$('.accValidate').each(function() {
$(this).rules({
required: true,
messages: {
required: "This field is required",
}
});
});
//Add validation rule for dynamically generated email fields
$('.status').each(function() {
$(this).rules({
required: true,
messages: {
required: "This field is required",
}
});
});
$('.price').each(function() {
$(this).rules({
required: true,
messages: {
required: "This field is required",
}
});
});
$('.debitValidate').each(function() {
$(this).rules({
required: true,
messages: {
required: "This field is required",
}
});
});
});
$("#tablogic").validate();
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<input type="button" class="add_Row adRow" id="add_Row" value="Add Row">
<div class="table-wrapper">
<table class="table table-bordered table-hover order-list" id="tab_logic">
<tbody>
<tr id="fst_row">
<td style="display: none;">
<input type="number" id="staticLedger" placeholder='Ledger Number' for="staticLedger" name="ledgerno" class="form-control" />
</td>
<td style="display: none;">
<input type="text" id="tdsrow" placeholder='Ledger Number' name="tdsrow" value="Y" th:value="Y" class="form-control" />
</td>
<td>
<input type="number" id="payacc_code" placeholder='Enter A/c code' for="acctcode" name="acctcode" class="form-control sel_text" />
</td>
<td>
<select class="form-control sel_sel" id="payacc" name="actname" for="actname">
</select>
</td>
<td>
<input type="text" class="form-control required" id="pay_narrat" name="narr" for="narr" data-toggle="modal" data-target="#narratModal" placeholder="Enter your text here" />
</td>
<td>
<input type="text" id="paydeb" name="debit" for="debit" placeholder='Debit Amount' data-action="sumDebit" class="form-control" readonly />
</td>
<td>
<input type="number" id="paycredit" name="credit" for="credit" placeholder='Credit Amount' data-action="sumCredit" class="form-control" tabindex="-1" readonly />
</td>
<td><button type="button" class="adRow" style="width:70%; cursor: not-allowed;">x</button>
</td>
</tr>
</tbody>
</table>
</div>
<!-- submit -->
<button type="submit" class="btn add-btn submit-btn load cashmainBtn" id="cashSub" th:value="Submit" tabindex="1">Submit</button>
Полный код на скрипке, пожалуйста, посетите - http://jsfiddle.net/joelshah/rqy1wnax/
Спасибо ..