mirror of
https://github.com/loewexy/pdnsmanager.git
synced 2025-01-30 17:31:36 +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>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<td></td>
|
<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><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="addContent" type="text" class="form-control input-sm" data-regex="^.+$"></td>
|
||||||
<td><input id="addPrio" type="text" class="form-control input-sm" size="1"></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"></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>
|
<td colspan="2"><button id="addButton" class="btn btn-success btn-sm"> Add </button></td>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -43,14 +43,8 @@ $(document).ready(function() {
|
||||||
$('#soa button[type=submit]').prop("disabled", false);
|
$('#soa button[type=submit]').prop("disabled", false);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#soa form input').bind("paste keyup change", function() {
|
$('#soa form input').bind("paste keyup change", regexValidate);
|
||||||
var regex = new RegExp($(this).attr('data-regex'));
|
$('#table-records>tfoot input').bind("paste keyup change", regexValidate);
|
||||||
if(!regex.test($(this).val()) && $(this).val().length > 0) {
|
|
||||||
$(this).parent().addClass("has-error");
|
|
||||||
} else {
|
|
||||||
$(this).parent().removeClass("has-error");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#searchType').select2({
|
$('#searchType').select2({
|
||||||
placeholder: "Filter...",
|
placeholder: "Filter...",
|
||||||
|
@ -304,6 +298,10 @@ function saveRecord() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRecord() {
|
function addRecord() {
|
||||||
|
if(!validateLine.call(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
name: $('#addName').val(),
|
name: $('#addName').val(),
|
||||||
type: $('#addType').val(),
|
type: $('#addType').val(),
|
||||||
|
@ -384,3 +382,24 @@ function enableFilter(enable) {
|
||||||
$('#searchContent').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