1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-28 12:30:00 +00:00

Table edit: validator routine to prevent empty fields working

This commit is contained in:
Ozzieisaacs 2020-06-11 21:36:12 +02:00
parent 1c681ee378
commit f26ccfe16c
2 changed files with 21 additions and 89 deletions

View File

@ -56,49 +56,31 @@ $(function() {
} }
}); });
}); });
/*$("#books-table").bootstrapTable({
});
test = $("#books-table").bootstrapTable('getOptions');
var column = test.columns[0]
column.forEach(function(item){
if ('editableValidate' in item) {
item.editable = {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
}
}
});
$("#books-table").bootstrapTable('refreshOptions', {columns: [column]});*/
var column = []; var column = [];
$('#table1 > thead > tr > th').each(function(){ $("#books-table > thead > tr > th").each(function() {
if ($(this).attr('data-edit')) { var element = {};
if ($(this).attr('data-edit-validate')) { if ($(this).attr("data-edit")) {
column.push({ element = {
editable: { editable: {
mode: 'inline', mode: "inline",
emptytext: "<span class='glyphicon glyphicon-plus'></span>", emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, }
} };
});
} else {
column.push({
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
}
});
}
} else {
column.push({});
} }
var validateText = $(this).attr("data-edit-validate");
if (validateText) {
element.editable.validate = function (value) {
if ($.trim(value) === "") return validateText;
};
}
column.push(element);
}); });
$("#table1").bootstrapTable({ $("#books-table").bootstrapTable({
sidePagination: "server", sidePagination: "server",
pagination: true, pagination: true,
paginationDetailHAlign: " hidden", paginationDetailHAlign: " hidden",
paginationHAlign: "left", paginationHAlign: "left",
/*url: window.location.pathname + "/../../ajax/listbooks",*/
idField: "id", idField: "id",
search: true, search: true,
showColumns: true, showColumns: true,
@ -109,56 +91,11 @@ $(function() {
maintainMetaData: true, maintainMetaData: true,
responseHandler: responseHandler, responseHandler: responseHandler,
columns: column, columns: column,
/*editable-mode="inline"
editable-emptytext="<span class='glyphicon glyphicon-plus'></span>">*/
/*columns: [
{},
{}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
}
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}],*/
formatNoMatches: function () { formatNoMatches: function () {
return ""; return "";
}, },
}); });
/*var $table = $('#books-table');
$('#books-table').bootstrapTable('getOptions')*/
/*$('#books-table').bootstrapTable('editable')*/
/*{ field: 'aimValue', title: 'Aim<br>Value', class: 'danger',editable: { mode: 'inline', validate: function (v) { return validateData(this, v); }, }, },*/
$("#domain_allow_submit").click(function(event) { $("#domain_allow_submit").click(function(event) {
event.preventDefault(); event.preventDefault();
$("#domain_add_allow").ajaxForm(); $("#domain_add_allow").ajaxForm();
@ -173,6 +110,7 @@ $(function() {
} }
}); });
}); });
$("#domain-allow-table").bootstrapTable({ $("#domain-allow-table").bootstrapTable({
formatNoMatches: function () { formatNoMatches: function () {
return ""; return "";
@ -398,9 +336,3 @@ function responseHandler(res) {
}); });
return res; return res;
} }
function validato(value) {
if($.trim(value) == '') return 'This field is required';
}
/*function validateVal(value) { if($.trim(value) == '') return 'This field is required'; }*/

View File

@ -6,7 +6,7 @@
data-editable-url="{{ url_for('editbook.edit_list_book', param=parameter)}}" data-editable-url="{{ url_for('editbook.edit_list_book', param=parameter)}}"
data-editable-title="{{ edit_text}}" data-editable-title="{{ edit_text}}"
data-edit="true" data-edit="true"
{% if validate %}data-edit-validate="true" {% endif %} {% if validate %}data-edit-validate="{{ _('This Field is Required') }}" {% endif %}
{% endif %} {% endif %}
>{{ show_text }}</th> >{{ show_text }}</th>
{%- endmacro %} {%- endmacro %}
@ -38,7 +38,7 @@
data-editable-emptytext="<span class='glyphicon glyphicon-plus'></span>" data-editable-emptytext="<span class='glyphicon glyphicon-plus'></span>"
</a--> </a-->
<div class="btn btn-default disabled" id="merge_books" aria-disabled="true">{{_('Merge selected books')}}</div> <div class="btn btn-default disabled" id="merge_books" aria-disabled="true">{{_('Merge selected books')}}</div>
<table id="table1" class="table table-no-bordered table-striped" <table id="books-table" class="table table-no-bordered table-striped"
data-url="{{url_for('web.list_books')}}"> data-url="{{url_for('web.list_books')}}">
<thead> <thead>
<tr> <tr>
@ -54,7 +54,7 @@
{{ text_table_row('series', _('Enter Series'),_('Series'), false) }} {{ text_table_row('series', _('Enter Series'),_('Series'), false) }}
<th data-field="series_index" id="series_index" data-sortable="true" {% if g.user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('editbook.edit_list_book', param='series_index')}}" data-editable="true" data-editable-title="{{_('Enter title')}}"{% endif %}>{{_('Series Index')}}</th> <th data-field="series_index" id="series_index" data-sortable="true" {% if g.user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('editbook.edit_list_book', param='series_index')}}" data-editable="true" data-editable-title="{{_('Enter title')}}"{% endif %}>{{_('Series Index')}}</th>
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }}
<th data-field="pubdate" data-type="date" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">Publishing Date</th> <th data-field="pubdate" data-type="date" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">_('Publishing Date')</th>
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }}
{% if g.user.role_edit() %} {% if g.user.role_edit() %}
<th data-align="right" data-formatter="EbookActions" data-switchable="false"></th> <th data-align="right" data-formatter="EbookActions" data-switchable="false"></th>