Update error handling for name and text

This commit is contained in:
Urban Rotnik 2020-01-16 13:30:05 +01:00
parent 0522b9b0a3
commit 218316bea2
3 changed files with 39 additions and 9 deletions

View file

@ -1,11 +1,40 @@
/* global GLOBAL_CONSTANTS textValidator I18n */
/* global GLOBAL_CONSTANTS I18n */
$.fn.dataTable.render.RowNameValidator = function($input) {
return textValidator(undefined, $input, 1, GLOBAL_CONSTANTS.NAME_MAX_LENGTH);
var $inputContainer = $input.closest('.sci-input-container');
var value = $input.val();
var errorText;
if (value === '') {
errorText = I18n.t('repositories.table.name.errors.is_empty');
} else if (value.length > GLOBAL_CONSTANTS.NAME_MAX_LENGTH) {
errorText = I18n.t('repositories.table.name.errors.too_long', { max_length: GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB });
}
if (errorText) {
$inputContainer.addClass('error');
$inputContainer.attr('data-error-text', errorText);
return false;
}
$inputContainer.removeClass('error');
return true;
};
$.fn.dataTable.render.RepositoryTextValueValidator = function($input) {
return textValidator(undefined, $input, 0, GLOBAL_CONSTANTS.TEXT_MAX_LENGTH);
var $inputContainer = $input.closest('.sci-input-container');
var value = $input.val();
var errorText;
if (value.length > GLOBAL_CONSTANTS.TEXT_MAX_LENGTH) {
errorText = I18n.t('repositories.table.text.errors.too_long', { max_length: GLOBAL_CONSTANTS.TEXT_MAX_LENGTH });
$inputContainer.addClass('error');
$inputContainer.attr('data-error-text', errorText);
return false;
}
$inputContainer.removeClass('error');
return true;
};
$.fn.dataTable.render.RepositoryListValueValidator = function() {

View file

@ -35,12 +35,6 @@ var renderFormError = function(ev, input, errMsgs, clearErr, errAttributes) {
})).join('<br />');
if ($(input).hasClass('sci-input-field')) {
$(input).closest('.sci-input-container').addClass('error');
$(input).closest('.sci-input-container').attr('data-error-text', errorText);
return;
}
// Mark error form group
var $formGroup = $(input).closest('.form-group');
if (!$formGroup.hasClass('has-error')) {

View file

@ -1058,6 +1058,8 @@ en:
assets:
select_file_btn: "Select File (Max %{max_size} MB)..."
text:
errors:
:too_long: "Text is too long (maximum is %{max_length} characters)"
enter_text: "Enter text"
number:
enter_number: "Enter number"
@ -1071,6 +1073,11 @@ en:
errors:
set_all_or_none: 'Needs to set both or none'
not_valid_range: 'Range is not valid.'
name:
errors:
too_long: "Item name is too long (maximum is %{max_length} characters)"
is_empty: "Item name should be filled"
add_new_record: "New item"
import_records:
import: 'Import'