From f26ccfe16c364c475815f0485eae1b7b0493a8b0 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Thu, 11 Jun 2020 21:36:12 +0200 Subject: [PATCH] Table edit: validator routine to prevent empty fields working --- cps/static/js/table.js | 104 ++++++---------------------------- cps/templates/book_table.html | 6 +- 2 files changed, 21 insertions(+), 89 deletions(-) diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 33bc2897..949f93f2 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -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 = []; - $('#table1 > thead > tr > th').each(function(){ - if ($(this).attr('data-edit')) { - if ($(this).attr('data-edit-validate')) { - column.push({ - editable: { - mode: 'inline', - emptytext: "", - validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, - } - }); - } else { - column.push({ - editable: { - mode: 'inline', - emptytext: "", - } - }); - } - } else { - column.push({}); + $("#books-table > thead > tr > th").each(function() { + var element = {}; + if ($(this).attr("data-edit")) { + element = { + editable: { + mode: "inline", + emptytext: "", + } + }; + } + 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", pagination: true, paginationDetailHAlign: " hidden", paginationHAlign: "left", - /*url: window.location.pathname + "/../../ajax/listbooks",*/ idField: "id", search: true, showColumns: true, @@ -109,56 +91,11 @@ $(function() { maintainMetaData: true, responseHandler: responseHandler, columns: column, - /*editable-mode="inline" - editable-emptytext="">*/ - /*columns: [ - {}, - {}, { - editable: { - mode: 'inline', - emptytext: "", - 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: "", - validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, - }, - }, { - editable: { - mode: 'inline', - emptytext: "", - validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, - }, - }, { - editable: { - mode: 'inline', - emptytext: "", - validate: function (value) { if($.trim(value) == '') return 'This field is required'; }, - }, - }],*/ formatNoMatches: function () { return ""; }, }); - /*var $table = $('#books-table'); - $('#books-table').bootstrapTable('getOptions')*/ - /*$('#books-table').bootstrapTable('editable')*/ - /*{ field: 'aimValue', title: 'Aim
Value', class: 'danger',editable: { mode: 'inline', validate: function (v) { return validateData(this, v); }, }, },*/ - - $("#domain_allow_submit").click(function(event) { event.preventDefault(); $("#domain_add_allow").ajaxForm(); @@ -173,6 +110,7 @@ $(function() { } }); }); + $("#domain-allow-table").bootstrapTable({ formatNoMatches: function () { return ""; @@ -398,9 +336,3 @@ function responseHandler(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'; }*/ diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html index 3801bbe5..ee349c05 100644 --- a/cps/templates/book_table.html +++ b/cps/templates/book_table.html @@ -6,7 +6,7 @@ data-editable-url="{{ url_for('editbook.edit_list_book', param=parameter)}}" data-editable-title="{{ edit_text}}" data-edit="true" - {% if validate %}data-edit-validate="true" {% endif %} + {% if validate %}data-edit-validate="{{ _('This Field is Required') }}" {% endif %} {% endif %} >{{ show_text }} {%- endmacro %} @@ -38,7 +38,7 @@ data-editable-emptytext=""
{{_('Merge selected books')}}
- @@ -54,7 +54,7 @@ {{ text_table_row('series', _('Enter Series'),_('Series'), false) }} {{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }} - + {{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }} {% if g.user.role_edit() %}
{{_('Series Index')}}Publishing Date_('Publishing Date')