Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created September 24, 2012 20:18
Show Gist options
  • Save netsi1964/3778099 to your computer and use it in GitHub Desktop.
Save netsi1964/3778099 to your computer and use it in GitHub Desktop.
Dynamicweb js validation of create user
// 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