Skip to content

Commit 591473e

Browse files
author
shankarThiyagaraajan
committed
- Improved error scroll.
1 parent d851622 commit 591473e

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/js/multi_formValidator.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function jsValidator() {
4848
this.option = false;
4949
// To apply global validator.
5050
this.onChange = false;
51+
this.validateResponse = false;
5152
/*
5253
* Initiating the Validator.
5354
*/
@@ -61,6 +62,7 @@ function jsValidator() {
6162
this.onChange = option.onChange;
6263
// Update default response "class".
6364
if ('undefined' === typeof option.errorClass) option.errorClass = 'js-error-cop';
65+
this.validateResponse = new validationResponse();
6466
// Update "jsSettings" to global object.
6567
this.jsSettings = new jsSettings().init(option);
6668
// Update "jsForm" to global object.
@@ -139,9 +141,9 @@ function jsValidator() {
139141
}
140142
}
141143
}
142-
if (false == this.initialLoad) new validationResponse().init(errorList, this.option);
144+
if (false == this.initialLoad) this.validateResponse.init(errorList, this.option);
143145
this.initialLoad = false;
144-
helper.scrollToError();
146+
helper.scrollToError(this.validateResponse);
145147
return status;
146148
};
147149
/*
@@ -830,9 +832,9 @@ var helper = {
830832
/*
831833
* To Scroll Up / Down to notify the item that have validation message.
832834
*/
833-
scrollToError: function () {
835+
scrollToError: function (validateResponse) {
834836
var dummy_id = '__header_error_target_temp';
835-
var active_class = new validationResponse().getClass();
837+
var active_class = validateResponse.getClass();
836838

837839
if (false === active_class) {
838840
jsLogger.out('Active Class Error', 'ACTIVE CLASS NOT DEFINED, GET :' + active_class);
@@ -842,12 +844,20 @@ var helper = {
842844
if (0 === document.getElementsByClassName(active_class).length) return false;
843845
// Getting current ID of the element.
844846
var active_id = document.getElementsByClassName(active_class)[0].id;
845-
// Update first element with dummy indec ID.
847+
// Update first element with dummy index ID.
846848
document.getElementsByClassName(active_class)[0].setAttribute('id', dummy_id);
847849
// Forming ID.
848-
var id = '#' + document.getElementsByClassName(active_class)[0].id;
850+
var id = document.getElementsByClassName(active_class)[0].id;
851+
// Retrieve the element name.
852+
var elem_name = active_id.replace('_new1_1_1xv_resp', '');
853+
// Taking active element to navigate.
854+
var top = document.getElementsByName(elem_name)[0].offsetTop;
855+
// Format as ID.
856+
id = '#' + id;
849857
// Navigate to ID.
850-
window.location.href = id;
858+
// window.location.href = id;
859+
// Scroll to error element as close as possible.
860+
window.scroll(0, parseInt(top) - 15);
851861
// Restore with actual ID.
852862
document.getElementsByClassName(active_class)[0].setAttribute('id', active_id);
853863
// Remove the navigated value.

0 commit comments

Comments
 (0)