Commit 44cecc62 authored by Tino Goratsch's avatar Tino Goratsch

refactored the JavaScript logic of the AJAX form handling

parent 418914cc
......@@ -20,12 +20,12 @@
<label for="title" class="col-sm-2 control-label required">{lang t="files|title"}</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120" required>
</div>
</div>
{block FILES_FILE_UPLOAD}
<div class="form-group">
<label for="file-internal" class="col-sm-2 control-label">{lang t="files|filename"}</label>
<label for="file-internal" class="col-sm-2 control-label required">{lang t="files|filename"}</label>
<div class="col-sm-10">
<div class="checkbox">
......@@ -58,12 +58,12 @@
</div>
</div>
<div class="form-group">
<label for="text" class="col-sm-2 control-label">{lang t="system|description"}</label>
<label for="text" class="col-sm-2 control-label required">{lang t="system|description"}</label>
<div class="col-sm-10">{wysiwyg name="text" value="`$form.text`" height="200" toolbar="simple"}</div>
</div>
<div class="form-group">
<label for="cat" class="col-sm-2 control-label">{lang t="categories|category"}</label>
<label for="cat" class="col-sm-2 control-label required">{lang t="categories|category"}</label>
<div class="col-sm-10">{$categories}</div>
</div>
......
......@@ -22,4 +22,4 @@
<input class="form-control" type="url" name="file_external" id="file-external" value="" maxlength="120">
</div>
</div>
{/block}
\ No newline at end of file
{/block}
jQuery(document).ready(function ($) {
var $errorBox = $('#error-box');
// At first, remove all previous validation error states
$('form .form-group.has-error')
.removeClass('has-error')
.find('.validation-failed').remove();
// Next, highlight all input fields where the validation has failed
$errorBox.find('li').each(function () {
var $this = $(this),
errorClass = $this.data('error');
if (errorClass.length > 0) {
var $elem = $('[id|="' + errorClass + '"]').filter(':not([id$="container"])');
if ($elem.length > 0) {
// Add CSS class that the validation for this entry has failed
$elem.closest('div.form-group').addClass('has-error');
// Move the error message to the responsible input field(s)
// and remove the list item from the error box container
if ($elem.length == 1) {
$elem.closest('div').append('<small class="help-block validation-failed"><i class="glyphicon glyphicon-remove"></i> ' + $this.html() + '</small>');
$this.remove();
}
}
}
});
// if all list items have been removed, remove the error box container too
if ($errorBox.find('li').length == 0) {
$errorBox.remove();
}
// As the last step, select the tab where the first error has occurred
if ($('.tabbable').length > 0) {
var tabId = $('.tabbable .form-group.has-error:first').closest('.tab-pane').prop('id');
$('.tabbable .nav-tabs a[href="#' + tabId + '"]').tab('show');
}
});
jQuery(document).ready(function ($) {
const $window = $(window);
var $window = $(window);
$window.on('hashchange', function () {
const hash = location.hash,
var hash = location.hash,
$link = $('a[href="' + hash + '"]'),
$element = $(hash);
......@@ -16,4 +16,4 @@ jQuery(document).ready(function ($) {
if (location.hash) {
$window.trigger('hashchange');
}
});
\ No newline at end of file
});
......@@ -8,14 +8,5 @@
<li{if intval($key) === 0} data-error="{$key}"{/if}>{$value}</li>
{/foreach}
</ul>
{if $error_box.non_integer_keys === true}
{if $IS_AJAX === true}
{include_js module="system" file="error_box"}
{else}
{javascripts}
{include_js module="system" file="error_box"}
{/javascripts}
{/if}
{/if}
</div>
{/block}
\ No newline at end of file
{/block}
......@@ -5,13 +5,4 @@
<li{if intval($key) === 0} data-error="{$key}"{/if}>{$value}</li>
{/foreach}
</ul>
{if $error_box.non_integer_keys === true}
{if $IS_AJAX === true}
<script type="text/javascript" src="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/js/error_box.js"></script>
{else}
{javascripts}
<script type="text/javascript" src="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/js/error_box.js"></script>
{/javascripts}
{/if}
{/if}
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment