Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add length validation to text input #3193

Merged
merged 1 commit into from Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -60,6 +60,8 @@ Improvements
defined for the event (:issue:`2813`)
- Show warning box to inform that reviewer roles do not apply when an event
has no tracks (:issue:`2919`)
- Allow specifying min/max length for registration form text fields
(:issue:`3193`, thanks :user:`bpedersen2`)

Bugfixes
^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions indico/htdocs/js/indico/modules/registration/form/field.js
Expand Up @@ -758,6 +758,8 @@ ndRegForm.directive('ndTextField', function(url) {
scope.settings.fieldName = $T("Text");
scope.settings.size = true;
scope.settings.formData.push('length');
scope.settings.formData.push('maxLength');
scope.settings.formData.push('minLength');
}
};
});
Expand Down
Expand Up @@ -9,3 +9,19 @@
max="60">
<i class="info-helper" title="{{ 'Must be between 5 and 60' | i18n }}"></i>
</div>
<ng-if="field.inputType == 'text'>
<div class="regFormEditLine">
<label class="regFormDialogCaption">
{{ 'Max. length' | i18n }}
</label>
<input type="number" name="maxlength" ng-model="formData.maxLength" min="1" step="1">
<i class="info-helper" title="{{ 'Maximum allowed length' | i18n }}"></i>
</div>
<div class="regFormEditLine">
<label class="regFormDialogCaption">
{{ 'Min. length' | i18n }}
</label>
<input type="number" name="minlength" ng-model="formData.minLength" min="0" step="1">
<i class="info-helper" title="{{ 'Minimum required length' | i18n }}"></i>
</div>
</ng-if>
Expand Up @@ -5,10 +5,20 @@
size="{{ field.length || getDefaultFieldSetting('defaultTextFieldSize') }}"
ng-model="userdata[fieldName]"
ng-required="field.isRequired"
ng-maxlength="{{ field.maxLength }}"
ng-minlength="{{ field.minLength }}"
ng-class="{
hasError: validationStarted && nestedForm.$invalid
}"/>

<span ng-show="validationStarted && nestedForm.$invalid && nestedForm.$error.minlength" class="error-message-tag">
{{ 'Minimum length:' | i18n }} {{ field.minLength }}
</span>

<span ng-show="validationStarted && nestedForm.$invalid && nestedForm.$error.maxlength" class="error-message-tag">
{{ 'Maximum length:' | i18n }} {{ field.maxLength }}
</span>

<span ng-show="validationStarted && nestedForm.$invalid && nestedForm.$error.required && field.isRequired" class="error-message-tag">
{{ 'Field is mandatory' | i18n }}
</span>
Expand Down