Created
December 18, 2019 09:57
-
-
Save tejpaldev/92f1e16e45e4356940c02c43f6973f7d to your computer and use it in GitHub Desktop.
This file contains 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 Trim(x) { | |
return x.replace(/^\s+|\s+$/gm, ''); | |
} | |
function ClearFormValidation(formid) { | |
var $form = jQuery('#' + formid); | |
//reset jQuery Validate's internals | |
$form.validate().resetForm(); | |
//reset unobtrusive validation summary, if it exists | |
$form.find("[data-valmsg-summary=true]") | |
.removeClass("validation-summary-errors") | |
.addClass("validation-summary-valid") | |
.find("ul").empty(); | |
//reset unobtrusive field level, if it exists | |
$form.find("[data-valmsg-replace]") | |
.removeClass("field-validation-error") | |
.addClass("field-validation-valid") | |
.empty(); | |
return $form; | |
} | |
function ShowSuccessMessage(message) { | |
jQuery('#alertinfo > ul > li:first').html(message); | |
jQuery('div[role=alert]').hide(); | |
jQuery('#alertinfo').show(); | |
//setTimeout(function () { | |
// jQuery("#alertinfo").fadeOut("slow", function () { | |
// jQuery('#alertinfo').hide(); | |
// }); | |
//}, 30 * 1000); | |
jQuery('html, body').animate({ scrollTop: '0px' }, 300); | |
} | |
function HideAlertMessage() { | |
jQuery('#alerterror, #diverror').hide(); | |
jQuery('#alertinfo, #divsuccess').hide(); | |
} | |
function ShowErrorMessage(message) { | |
jQuery('#alerterror > ul > li:first').html(message); | |
jQuery('div[role=alert]').hide(); | |
jQuery('#alerterror').show(); | |
//setTimeout(function () { | |
// jQuery("#alerterror").fadeOut("slow", function () { | |
// jQuery('#alerterror').hide(); | |
// }); | |
//}, 30 * 1000); | |
jQuery('html, body').animate({ scrollTop: '0px' }, 300); | |
} | |
jQuery(function () { | |
jQuery('input[type=button]', 'input[type=submit]', 'button').click(function () { | |
HideAlertMessage(); | |
}); | |
jQuery('form').submit(function () { | |
HideAlertMessage(); | |
}); | |
jQuery(".validateform").validationEngine({ maxErrorsPerField: 1, showArrow: true, promptPosition: "topRight" }); | |
jQuery.each(jQuery("input[type=text]"), function (index, element) { | |
var strlength = jQuery(element).data("val-length-max"); | |
if (strlength != undefined) { | |
jQuery(element).attr('maxlength', strlength); | |
} | |
}); | |
jQuery('#alerterror-close').click(function () { | |
jQuery(this).parent().hide(); | |
}); | |
jQuery('#alertinfo-close').click(function () { | |
jQuery(this).parent().hide(); | |
}); | |
jQuery.ajaxSetup({ | |
cache: false, | |
error: function (x, status, error) { | |
if (x.status == 403 || x.status == 401) { | |
alert("Sorry, your session has expired. Please login again to continue"); | |
window.location.reload(); | |
} | |
else { | |
alert("An error occurred: " + status + "nError: " + error); | |
} | |
} | |
}); | |
}); | |
function validateEmail(sEmail) { | |
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; | |
if (filter.test(sEmail)) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
function ClearForm($form) { | |
$form.find('input[type=text]').val(''); | |
$form.find('textarea').val(''); | |
$form.find('select').val(''); | |
} | |
jQuery.SetInputMaxLength = function (scope) { | |
if (scope == '' || scope == undefined) { | |
scope = 'body'; | |
} | |
jQuery(scope + " input[type=text][data-val-length-max]").each(function () { | |
jQuery(this).attr('maxlength', jQuery(this).attr('data-val-length-max')); | |
}); | |
}; | |
jQuery.fn.numericonly = function () { | |
jQuery(this).keydown(function (e) { | |
// Allow: backspace, delete, tab, escape, enter and . | |
if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || | |
// Allow: Ctrl+A, Command+A | |
(e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) || | |
// Allow: home, end, left, right, down, up | |
(e.keyCode >= 35 && e.keyCode <= 40)) { | |
// let it happen, don't do anything | |
return; | |
} | |
// Ensure that it is a number and stop the keypress | |
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { | |
e.preventDefault(); | |
} | |
}); | |
} | |
jQuery.fn.converttoupper = function () { | |
jQuery(this).keyup(function (e) { | |
if (e.which >= 97 && e.which <= 122) { | |
var newKey = e.which - 32; | |
// I have tried setting those | |
e.keyCode = newKey; | |
e.charCode = newKey; | |
} | |
jQuery(this).val((jQuery(this).val()).toUpperCase()); | |
}); | |
} | |
jQuery.Numeric = function (scope) { | |
if (scope == '' || scope == undefined) { | |
scope = 'body'; | |
} | |
jQuery(scope + " .numeric").numeric(); | |
jQuery(scope + " .integer").numeric(false, null); | |
jQuery(scope + " .positive").numeric({ negative: false }, null); | |
jQuery(scope + " .positive-integer").numeric({ decimal: false, negative: false }, null); | |
} | |
jQuery(function () { | |
jQuery('.uppercase').converttoupper(); | |
jQuery.Numeric(); | |
}); | |
function FnEnabledDisabledDropdown(ddlID, disabled) { | |
if (disabled) { | |
var selectedValue = $('#' + ddlID).val(); | |
$('#' + ddlID + ' option[value!="' + selectedValue + '"]').prop('disabled', true); | |
$('#' + ddlID + ' option[value!="' + selectedValue + '"]').css('display', 'none'); | |
} | |
else { | |
$('#' + ddlID + ' option').prop('disabled', false); | |
$('#' + ddlID + ' option').css('display', 'block'); | |
} | |
} | |
function ShowSuccessMessageNew(divname, message) { | |
jQuery('#' + divname + ' #alertinfo > ul > li:first').html(message); | |
jQuery('#' + divname + ' div[role=alert]').hide(); | |
jQuery('#' + divname + ' #alertinfo').show(); | |
setTimeout(function () { | |
jQuery('#' + divname + " #alertinfo").fadeOut("slow", function () { | |
jQuery('#' + divname + ' #alertinfo').hide(); | |
}); | |
}, 30 * 1000); | |
} | |
function ShowErrorMessageNew(divname, message) { | |
jQuery('#' + divname + ' #alerterror > ul > li:first').html(message); | |
jQuery('#' + divname + ' div[role=alert]').hide(); | |
jQuery('#' + divname + ' #alerterror').show(); | |
setTimeout(function () { | |
jQuery('#' + divname + " #alerterror").fadeOut("slow", function () { | |
jQuery('#' + divname + ' #alerterror').hide(); | |
}); | |
}, 30 * 1000); | |
} | |
function FnOpenNewWindow(html) { | |
try { | |
var WindowObject = window.open("about:blank", "_blank", "width=900,height=425,top=100,left=100,toolbars=no,scrollbars=yes,status=no,resizable=yes"); | |
WindowObject.document.write(html); | |
WindowObject.document.close(); | |
WindowObject.focus(); | |
} | |
catch (e) { | |
} | |
} | |
function IsNullOrEmpty(str) { | |
var returnValue = false; | |
if (!str | |
|| str == null | |
|| str === 'null' | |
|| str === '' | |
|| str === '{}' | |
|| str === 'undefined' | |
|| str.length === 0) { | |
if (str.trim().length > 0) { | |
returnValue = true; | |
} else { | |
returnValue = false; | |
} | |
} | |
return returnValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment