Skip to content

Commit

Permalink
More convenient way for changing options (outside the script); versio…
Browse files Browse the repository at this point in the history
…n bump
  • Loading branch information
Robyer committed Dec 11, 2015
1 parent 20e7538 commit b0a277e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion live-form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/

Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit b0a277e

Please sign in to comment.