From b0a277e4b16e0c953399bb34c139c779a2d4795f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= <robyer@seznam.cz> Date: Fri, 11 Dec 2015 12:42:14 +0100 Subject: [PATCH] More convenient way for changing options (outside the script); version bump --- README.md | 14 ++++++++++++++ live-form-validation.js | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fdf451..a8555c3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,20 @@ The script already contains the `netteForms.js` file, so don't use it again and Options ------- +You can change default options by calling `LiveForm.setOptions({ ... });` after including the script. Give only options that you want to change. For example: + +```js +<script src="/js/live-form-validation.js"></script> +<script> + LiveForm.setOptions({ + messageErrorPrefix: 'Error: ', + wait: 500 + }); +</script> +``` + +### Available options + - **showMessageClassOnParent** - CSS class of control's parent where error/valid class should be added; or "false" to use control directly - **controlErrorClass** - CSS class for an invalid control - **controlValidClass** - CSS class for a valid control diff --git a/live-form-validation.js b/live-form-validation.js index 0ef19eb..8817bee 100644 --- a/live-form-validation.js +++ b/live-form-validation.js @@ -2,7 +2,7 @@ * Live Form Validation for Nette Forms 2.3 * * @author Robert Pösel, zakrava, Radek Ježdík, MartyIX, David Grudl - * @version 1.6.0 + * @version 1.6.1 * @url https://github.com/Robyer/nette-live-form-validation/ */ @@ -51,6 +51,14 @@ var LiveForm = { forms: { } }; +LiveForm.setOptions = function(userOptions) { + for (prop in userOptions) { + if (Object.prototype.hasOwnProperty.call(this.options, prop)) { + this.options[prop] = userOptions[prop]; + } + } +} + LiveForm.isSpecialKey = function(k) { // http://stackoverflow.com/questions/7770561/jquery-javascript-reject-control-keys-on-keydown-event return (k == 20 /* Caps lock */