Created
September 24, 2012 20:18
-
-
Save netsi1964/3778099 to your computer and use it in GitHub Desktop.
Dynamicweb js validation of create user
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
// Find the code here: https://gist.github.com/3778099 | |
function addClientSideValidation(sFormSelector, required, sErrorMessage) { | |
if (typeof jQuery==='undefined') { | |
alert('jQuery is required'); | |
return false; | |
}; | |
required = (required.length===0) ? ['UserManagement_Form_Company', 'UserManagement_Form_Name', 'UserManagement_Form_Phone', 'UserManagement_Form_Address', 'UserManagement_Form_Zip', 'UserManagement_Form_City', 'UserManagement_Form_Country'] : required; | |
jQuery(sFormSelector).submit(function(evt) { | |
var bValid = true; | |
for (var i = 0; i < required.length; i++) { | |
var $this = jQuery('#' + required[i]); | |
$this.removeClass('error'); | |
if (jQuery.trim($this.val()).length === 0) { | |
if (bValid) $this.trigger('click'); | |
bValid = false; | |
$this.addClass('error'); | |
}; | |
}; | |
if (sErrorMessage!=='' && !bValid) { | |
alert(sErrorMessage); | |
evt.preventDefault(); | |
}; | |
return bValid; | |
}); | |
}; | |
addClientSideValidation('form[name="formName"]', '', 'The marked fields are required'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment