mirror of
https://github.com/loewexy/pdnsmanager.git
synced 2025-01-29 16:49:57 +01:00
Added validity check for adding record
This commit is contained in:
parent
17e3cf908d
commit
6358babe37
2 changed files with 31 additions and 12 deletions
|
@ -146,11 +146,11 @@ limitations under the License.
|
|||
</tbody>
|
||||
<tfoot>
|
||||
<td></td>
|
||||
<td><input id="addName" type="text" class="form-control input-sm"></td>
|
||||
<td><input id="addName" type="text" class="form-control input-sm" data-regex="^([^.]+\.)*[^.]+$"></td>
|
||||
<td><select id="addType" class="form-control" style="width: 70%;"></select></td>
|
||||
<td><input id="addContent" type="text" class="form-control input-sm"></td>
|
||||
<td><input id="addPrio" type="text" class="form-control input-sm" size="1"></td>
|
||||
<td><input id="addTtl" type="text" class="form-control input-sm" size="3"></td>
|
||||
<td><input id="addContent" type="text" class="form-control input-sm" data-regex="^.+$"></td>
|
||||
<td><input id="addPrio" type="text" class="form-control input-sm" size="1" data-regex="^[0-9]+$"></td>
|
||||
<td><input id="addTtl" type="text" class="form-control input-sm" size="3" data-regex="^[0-9]+$"></td>
|
||||
<td colspan="2"><button id="addButton" class="btn btn-success btn-sm"> Add </button></td>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
|
|
@ -43,14 +43,8 @@ $(document).ready(function() {
|
|||
$('#soa button[type=submit]').prop("disabled", false);
|
||||
});
|
||||
|
||||
$('#soa form input').bind("paste keyup change", function() {
|
||||
var regex = new RegExp($(this).attr('data-regex'));
|
||||
if(!regex.test($(this).val()) && $(this).val().length > 0) {
|
||||
$(this).parent().addClass("has-error");
|
||||
} else {
|
||||
$(this).parent().removeClass("has-error");
|
||||
}
|
||||
});
|
||||
$('#soa form input').bind("paste keyup change", regexValidate);
|
||||
$('#table-records>tfoot input').bind("paste keyup change", regexValidate);
|
||||
|
||||
$('#searchType').select2({
|
||||
placeholder: "Filter...",
|
||||
|
@ -304,6 +298,10 @@ function saveRecord() {
|
|||
}
|
||||
|
||||
function addRecord() {
|
||||
if(!validateLine.call(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = {
|
||||
name: $('#addName').val(),
|
||||
type: $('#addType').val(),
|
||||
|
@ -383,4 +381,25 @@ function enableFilter(enable) {
|
|||
$('#searchType').prop("disabled", true);
|
||||
$('#searchContent').prop("disabled", true);
|
||||
}
|
||||
}
|
||||
|
||||
function regexValidate() {
|
||||
var regex = new RegExp($(this).attr('data-regex'));
|
||||
if(!regex.test($(this).val())) {
|
||||
$(this).parent().addClass("has-error");
|
||||
} else {
|
||||
$(this).parent().removeClass("has-error");
|
||||
}
|
||||
}
|
||||
|
||||
function validateLine() {
|
||||
$(this).parent().parent().find('input[data-regex]').change();
|
||||
var errors = 0;
|
||||
$(this).parent().parent().find('input[data-regex]').each(function() {
|
||||
if($(this).parent().hasClass('has-error')) {
|
||||
errors++;
|
||||
}
|
||||
});
|
||||
|
||||
return errors <= 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue