Created
October 27, 2017 08:04
-
-
Save ps-team/7438b6355738b6eda76d9373180da102 to your computer and use it in GitHub Desktop.
Scroll to first failed validation input in a Contensis Form. ***required JQuery.scrollIntoView***
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!(function($, d) { | |
'use strict'; | |
var debug = false; | |
$(function() { | |
$('[id*=btnSubmitForm]').click(onSubmitClick); | |
}); | |
function onSubmitClick(e) { | |
var formID = returnFormId($(this).attr('id')); | |
var pageID = $(this).parent().parent().attr('id'); | |
var currentpageId = returnPageId(pageID).split("-")[0]; | |
debug && console.log("btnSubmitForm clicked"); | |
existsError(currentpageId, formID); | |
} | |
function existsError(pageId, formId) { | |
var $inputsValidFailed = $("#formpage_" + pageId + "-" + formId).find(".sys_cms-form-error:visible"); | |
debug && console.log("existsError"); | |
debug && console.log("$inputsValidFailed"); | |
debug && console.log($inputsValidFailed); | |
if ($inputsValidFailed.length > 0) { | |
var elToScrollTo = $($inputsValidFailed[0]).closest('li'); | |
elToScrollTo.scrollIntoView && elToScrollTo.scrollIntoView(); | |
} | |
} | |
function returnFormId(objId) { | |
var IdArray = objId.split('_'); | |
return IdArray[1]; | |
} | |
function returnPageId(objId) { | |
var IdArray = objId.split('_'); | |
return IdArray[1]; | |
} | |
})(jQuery, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment