1.1.9 • Published 4 years ago

jquery.niceform v1.1.9

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

NiceForm

The jQuery plugin for validation and post form data to server (http://ducdhm.github.io/jquery.niceform/)

Shortcuts

Dependencies

Rules

NameSelectorDescription
Required.requiredInvalid when value of field is blank or same as placeholder attribute
Date.dateInvalid when value of field is not matched with locale.date format from configuration
Time.timeInvalid when value of field is not matched with locale.time format from configuration
DateTime.datetimeInvalid when value of field is not matched with locale.datetime format from configuration
Email.emailInvalid when value of field is not matched with regex.email regular expression from configuration
Number.numberInvalid when value of field is not number/digit/numeric
Url.urlInvalid when value of field is not matched with regex.url regular expression from configuration
Password.passwordInvalid when value of field is not matched with password from configuration
Repassword.repasswordInvalid when value of field is not matched with .password field
Regex.regexInvalid when value of field is not matched with data-regex regular expression from attribute of field. Error message of this rule will be specified in data-regex-message attribute
Regex.simpleInvalid when value of field is not matched with regex.url regular expression from configuration
Regex.really-simpleInvalid when value of field is not matched with regex.url regular expression from configuration

Note:

  • You can ignore validation rules by using data-ignore=validate for your fields
  • You can combined Required rule with other rules
  • All rules except Required will be validated if value of field is not blank

Configuration

OptionTypeDescription
postFormEnabledBooleanAllow NiceForm post form data to server by using AJAX or not. Default: true
postUrlStringURL to post form data. Default: null
ajaxObjectAJAX options to post form data Default: { type: 'POST', dataType: 'JSON' }
passwordObjectPassword validator options. Default: source code
regexObjectRegular expression options. Default: source code
animationDurationNumberAnimation duration in millisecond. Default: 200
localeObjectLocale options. Default: source code
validateFunctionFunction to validate the form fields which are not in built-in list. Need to return array of invalid fields or null if valid. Default: null. Params: form and options. Return: `Array
showErrorFunctionFunction to show error states when form is invalid. Default: source code. Params: form, errorFields and options
hideErrorFunctionFunction to hide error states before validating form. Default: source code. Params: form, errorFields and options
processAjaxResponseFunctionFunction to process ajax response from server to decide response is success or not. Default: source code. Params: resp, form, and options. Return: Boolean
onValidFunctionCallback will be called when form is valid. Default: null. Params: form and options
onInvalidFunctionCallback will be called when form is invalid. Default: null. Params: form and options
onBeforeValidateFunctionCallback will be called before validating form. Default: null. Params: form and options
onBeforeSerializeFormFunctionCallback will be called before serializing form. Default: null. Params: form and options
onBeforePostFormFunctionCallback will be called before posting form. Default: null. Params: form and options
onAjaxSuccessFunctionCallback will be call if processAjaxResponse return true. Default: source code. Params: resp, form and options
onAjaxErrorFunctionCallback will be call if processAjaxError return false or $.ajax gets error or an unknown issue occurs. Default: source code. Params: jqXhr, form and options

Methods

NameParams (ParamType: paramName)Description
clearValueString: controlSelectorClear value, uncheck and set selected index is -1 of all text boxes, textareas, select boxes, radio buttons, checkboxes or provided controlSelector.NOTE: Not effect with element data-ignore="clear"
enableFormEnable all form controls include textbox, textarea, select box, radio button, checkbox and button.NOTE: Set readonly=false for all elements which do not contain data-origin-readonly
disableFormDisable all form controls include textbox, textarea, select box, radio button, checkbox and button.NOTE: Set readonly=true and data-origin-readonly=true for elements which are readonly as default
showMessageString: type String: title String: messageBuilt-in message method of NiceForm. type can be success, info, warning, error or danger
showSuccessMessageString: messageShortcut of showMessage with type is success and title is Success!
showErrorMessageString messageShortcut of showMessage with type is error and title is Error!
hideMessageHide built-in message
getOptionsGet options/configuration of NiceForm
showElementjQuery: elementShow specified element with fadeIn and slideDown effects
hideElementjQuery: elementHide specified element with fadeOut and slideUp effects

Note: There are many ways to call method

$('#form-id').niceform('methodName', param1, param2, ...);

or

var niceform = $('#form-id').niceform(options); // Get NiceForm instance when initializing
niceform.methodName(param1, param2, ...);

or

var niceform = $('#form-id').data('niceform'); // Get NiceForm instance via `data` attribute
niceform.methodName(param1, param2, ...);

Custom message

To custom message for a specified field, just need data-${rule}-message attribute. Example:

<input type="text" class="required email" name="email" data-required-message="Email address is mandatory!" data-email-message="Email address is invalid!" /> 

License

Please read at here

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago