update form validation for customers

Signed-off-by: Maurice Preuß (envoyr) <envoyr@froxlor.org>
This commit is contained in:
Maurice Preuß (envoyr)
2022-12-27 15:21:53 +01:00
parent 03a39ca69f
commit 37980060ea
10 changed files with 70 additions and 39 deletions

View File

@@ -2,7 +2,7 @@
{% import "Froxlor/form/formfields.html.twig" as formfields %}
<form action="{{ formaction|default("") }}" method="post" enctype="multipart/form-data" class="form">
<form action="{{ formaction|default("") }}" {% if form_data.id is defined %}id="{{ form_data.id }}"{% endif %} method="post" enctype="multipart/form-data" class="form">
{% for sid,section in form_data.sections %}
{% if section.visible is not defined or (section.visible is defined and section.visible == true) %}
<div class="card mb-3" id="{{ idprefix }}{{ sid }}">
@@ -48,4 +48,9 @@
{% endif %}
<span class="text-danger">*</span> {{ lng('panel.mandatoryfield') }}
</form>
{# add translation for custom validations #}
{% if form_data.id is defined and form_data.id in ['customer_add', 'customer_edit'] %}
<script>$(function() { $.extend($.validator.messages, {required: "{{ lng('error.requiredfield') }}"}) });</script>
{% endif %}
{% endmacro %}

View File

@@ -73,28 +73,6 @@
<small class="text-info">{{ field.note|raw }}</small>
{% endif %}
{% if field.mandatory_ex is not empty and field.mandatory_ex is iterable and field.mandatory_ex|length > 0 %}
<script>
$(function () {
$('#{{ id }}').attr('required', true);
$('#{{ id }}').trigger('change');
$('#{{ id }}').on('change', function(e) {
if ($(this).val().length > 0) {
{% for mex in field.mandatory_ex %}
$('#{{ mex }}').attr('required', false);
{% endfor %}
$('#{{ id }}').attr('required', true);
} else {
{% for mex in field.mandatory_ex %}
$('#{{ mex }}').attr('required', true);
{% endfor %}
$('#{{ id }}').attr('required', false);
}
});
});
</script>
{% endif %}
{% if norow == false and (field.type != 'hidden' or (field.type == 'hidden' and field.display is defined and field.display is not empty)) %}
</div>
</div>

View File

@@ -0,0 +1,24 @@
$(document).ready(function() {
$('#customer_add,#customer_edit').each(function(){
$(this).validate({
rules:{
'name':{
required:function(){
return $('#company').val().length === 0 || $('#firstname').val().length > 0;
}
},
'firstname':{
required:function(){
return $('#company').val().length === 0 || $('#name').val().length > 0;
}
},
'company':{
required:function(){
return $('#name').val().length === 0
&& $('#firstname').val().length === 0;
}
}
},
});
});
});

View File

@@ -5,6 +5,7 @@ import Chart from 'chart.js/auto';
// set jquery & bootstrap & chart
global.$ = require('jquery');
global.validation = require('jquery-validation');
global.bootstrap = require('bootstrap');
window.Chart = Chart;
@@ -27,16 +28,17 @@ $(function () {
});
// Load components
require('./components/global')
require('./components/search')
require('./components/newsfeed')
require('./components/updatecheck')
require('./components/customer')
require('./components/tablecolumns')
require('./components/ipsandports')
require('./components/domains')
require('./components/configfiles')
require('./components/apikeys')
require('./components/install')
require('./components/configfiles')
require('./components/customer')
require('./components/dnseditor')
require('./components/domains')
require('./components/global')
require('./components/install')
require('./components/ipsandports')
require('./components/newsfeed')
require('./components/search')
require('./components/tablecolumns')
require('./components/traffic')
require('./components/updatecheck')
require('./components/validation')