Skip to content

Commit 43de252

Browse files
authored
Merge pull request #6 from kloverde/1.1
Merge branch 1.1
2 parents f87fb03 + b663939 commit 43de252

28 files changed

+3045
-252
lines changed

.classpath

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<!--
4+
The libraries comprising RestrictedTextField-dep are:
5+
6+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-api/3.0.1/1b9f071c79d7ae546c4c4d3398c9cc5828cf2864/selenium-api-3.0.1.jar"/>
7+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-chrome-driver/3.0.1/3ad968cea2754de3009d8a19f3adc52ec94915b3/selenium-chrome-driver-3.0.1.jar"/>
8+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-edge-driver/3.0.1/ec33db1d7e5a1ab2da248635366920a35a51465a/selenium-edge-driver-3.0.1.jar"/>
9+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-firefox-driver/3.0.1/653064ccbd3083113ca1e8b5d9c8c822e5822d83/selenium-firefox-driver-3.0.1.jar"/>
10+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-ie-driver/3.0.1/e4b241603a368d877e406790eae4bee417814fc6/selenium-ie-driver-3.0.1.jar"/>
11+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.seleniumhq.selenium/selenium-remote-driver/3.0.1/963199423ff445b2c09ef2d5469c964f9a628df3/selenium-remote-driver-3.0.1.jar"/>
12+
13+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/19.0/6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9/guava-19.0.jar"/>
14+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.2/733db77aa8d9b2d68015189df76ab06304406e50/httpclient-4.5.2.jar"/>
15+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.4/b31526a230871fbe285fbcbe2813f9c0839ae9b0/httpcore-4.4.4.jar"/>
16+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/>
17+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.3.1/ecb6e1f8e4b0e84c4b886c2f14a1500caf309757/gson-2.3.1.jar"/>
18+
<classpathentry kind="lib" path="C:/Users/Kurt/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-exec/1.3/8dfb9facd0830a27b1b5f29f84593f0aeee7773b/commons-exec-1.3.jar"/>
19+
-->
20+
21+
<classpathentry kind="src" path="SeleniumTester/src/test/java"/>
22+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
23+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
24+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/RestrictedTextField-dep"/>
25+
<classpathentry kind="output" path="bin"/>
26+
</classpath>

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
/.project
1+
/bin
2+
/build
3+
/node_modules
4+
/src/temp
5+
/SeleniumTester/.gradle
6+
/SeleniumTester/build

.project

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>jquery-RestrictedTextField</name>
4+
<comment/>
5+
<projects/>
6+
<natures>
7+
<nature>org.eclipse.jdt.core.javanature</nature>
8+
</natures>
9+
<buildSpec>
10+
<buildCommand>
11+
<name>org.eclipse.jdt.core.javabuilder</name>
12+
<arguments/>
13+
</buildCommand>
14+
</buildSpec>
15+
<linkedResources/>
16+
</projectDescription>

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Release 1.1 (November 15, 2016)
2+
3+
* Fixes for money types
4+
* All money types automatically format on blur: values will be updated, if necessary, to always end in a period followed by two digits
5+
* Fixed issue with the int types which considered a negative sign by itself to be a valid value
6+
* Relaxed the int and float types/subtypes, and added strict versions of each. The relaxed versions accept leading/trailing zeros and negative zero; the strict versions do not.
7+
* Added a logging callback function as a configurable option
8+
* Throws an exception if invoked on something other than an input element
9+
* Added Selenium unit tests
10+
11+
112
# Release 1.0.1 (April 2, 2016)
213

314
* Minor under-the-hood improvement. No change to functionality.

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Source code contributions to this project are welcome. To increase the likelihood of your code being accepted,
2+
please follow these few rules:
3+
4+
1. Before beginning work on adding features, contact me at the e-mail address listed on my GitHub profile and
5+
tell me what you'd like to do. This will spare you from wasting time and effort if I disagree about the
6+
appropriateness of your proposed change.
7+
8+
2. Maintain the existing code formatting practices.
9+
10+
3. Use three spaces for indentation. DO NOT USE TABS FOR INDENTATION. In fact, don't use tabs for any kind
11+
of whitespace. This is so important that it gets its own rule, rather than being implicitly stated by
12+
Rule #2.
13+
14+
4. Include thorough, complete test coverage of your changes in SeleniumTester. If you don't include complete
15+
test coverage, your changes will not be accepted. If your changes are of a nature that no new tests are
16+
necessary (for example, you're tweaking an existing regular expression which already has test coverage and
17+
was failing in an obscure browser), include a note which mentions this. This will ensure that your
18+
changes are not automatically rejected.
19+
20+
5. Submit your changes through pull requests on GitHub. Code submissions sent by other means won't be
21+
accepted.

Gruntfile.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module.exports = function(grunt) {
2+
3+
grunt.initConfig( {
4+
//properties: {
5+
// props: "grunt.properties"
6+
//},
7+
8+
pkg: grunt.file.readJSON('package.json'),
9+
10+
uglify: {
11+
options: {
12+
banner: "/*! <%= pkg.name %> <%= grunt.template.today('yyyy-mm-dd') %> */\n"
13+
},
14+
15+
build: {
16+
src : "src/<%= pkg.name %>.js",
17+
dest : "build/<%= pkg.name %>.min.js"
18+
}
19+
},
20+
21+
// Gradle builds and runs the Selenium client (JUnit tests)
22+
exec: {
23+
"gradle-test": {
24+
cmd: function() {
25+
return "cd SeleniumTester && gradle clean test --stacktrace";
26+
}
27+
}
28+
},
29+
30+
// The Selenium server retrieves the test page via HTTP
31+
"http-server": {
32+
"dev": {
33+
root: ".",
34+
port: 8000,
35+
host: "127.0.0.1",
36+
cache: 0,
37+
showDir: true,
38+
autoIndex: true,
39+
ext: "html",
40+
runInBackground: true,
41+
openBrowser: false
42+
},
43+
44+
// This configuration is not used by the build process. It keeps the server running so that you can run SeleniumTester in a debugger.
45+
"debug": {
46+
root: ".",
47+
port: 8000,
48+
host: "127.0.0.1",
49+
cache: 0,
50+
showDir: true,
51+
autoIndex: true,
52+
ext: "html",
53+
runInBackground: false,
54+
openBrowser: false
55+
}
56+
},
57+
58+
// The Selenium server loads the test page and automates the browser per the requests from the Selenium client.
59+
// If you change the Selenium version here, be sure to update build.gradle in the SeleniumTester project.
60+
"start-selenium-server": {
61+
dev: {
62+
options: {
63+
autostop: false,
64+
downloadUrl: "https://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar",
65+
serverOptions: {},
66+
systemProperties: {}
67+
}
68+
}
69+
},
70+
71+
"stop-selenium-server": {
72+
dev: {}
73+
}
74+
} );
75+
76+
grunt.loadNpmTasks( "grunt-exec" );
77+
grunt.loadNpmTasks( "grunt-http-server" );
78+
grunt.loadNpmTasks( "grunt-selenium-server" );
79+
//grunt.loadNpmTasks( "grunt-properties-reader" );
80+
grunt.loadNpmTasks( "grunt-contrib-uglify" );
81+
82+
grunt.registerTask( "test", "Run unit tests", function() {
83+
grunt.task.run( "http-server:dev", "start-selenium-server:dev", "exec:gradle-test", "stop-selenium-server:dev" );
84+
} );
85+
};

README.md

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
RestrictedTextField v1.0.1
2-
==========================
1+
RestrictedTextField v1.1
2+
========================
33

44
See LICENSE for this software's licensing terms.
55

6-
ResrictedTextField is a jQuery plugin which enforces data formats on HTML text boxes. Data which doesn't match the declared format is rejected.
6+
ResrictedTextField is a jQuery plugin which uses regular expressions to validate HTML text fields. It allows you to reject invalid keystrokes or to allow them into the field. Fields are always validated on blur.
77

88

99
## Features
1010

1111
* Prevent invalid keystrokes or catch a validation failure event to handle it as you wish
12+
* Has 29 built-in types
13+
* Extendible: define your own types
14+
* Money types automatically format on blur to end in a decimal point and two digits
1215

13-
* Endlessly extendible: define your own types
14-
* Features 23 built-in types:
16+
17+
## Built-in Types
1518

1619
1. Alpha strings
1720
2. Uppercase alpha strings
@@ -28,22 +31,52 @@ ResrictedTextField is a jQuery plugin which enforces data formats on HTML text b
2831
13. Integers
2932
14. Positive integers
3033
15. Negative integers
31-
16. Floats
32-
17. Positive floats
33-
18. Negative floats
34-
19. Money
35-
20. Positive money
36-
21. Negative money
37-
22. Accounting money notation (negatives expressed by wrapping the value in parentheses)
38-
23. Negative accounting money
34+
16. Strict integers
35+
17. Strict positive integers
36+
18. Strict negative integers
37+
19. Floats
38+
20. Positive floats
39+
21. Negative floats
40+
22. Strict floats
41+
23. Strict positive floats
42+
24. Strict negative floats
43+
25. Money
44+
26. Positive money
45+
27. Negative money
46+
28. Accounting money notation (negatives expressed by wrapping the value in parentheses)
47+
29. Negative accounting money
48+
49+
50+
## What's the difference between integer/strict integer, float/strict float?
51+
52+
### Integer types:
53+
54+
* Zero can be negative
55+
56+
### Strict integer types:
57+
58+
* Zero cannot be negative
59+
60+
### Float types:
61+
62+
* Integers are valid
63+
* Zero is valid (0, 0.0, .0, 0000.000, etc.)
64+
* Zero can be negative
65+
66+
### Strict float types:
67+
68+
* Values must be floating-point
69+
* Zero is valid (0.0, .0, 0000.000, etc.)
70+
* Zero cannot be negative
3971

4072

4173
## Configuration
4274

4375
| Property | Description | Data Type | Valid Values | Default Value |
4476
| -------- | --------------|---------- |----------------------|---------------|
45-
| `type` | Text field type | string | alpha, upperAlpha, lowerAlpha, alphaSpace, upperAlphaSpace, lowerAlphaSpace, alphanumeric, upperAlphanumeric, lowerAlphanumeric, alphanumericSpace, upperAlphanumericSpace, lowerAlphanumericSpace, int, positiveInt, negativeInt, float, positiveFloat, negativeFloat, money, positiveMoney, negativeMoney, accountingMoney, negativeAccountingMoney| null |
77+
| `type` | Text field type. This is a required setting. | string | alpha, upperAlpha, lowerAlpha, alphaSpace, upperAlphaSpace, lowerAlphaSpace, alphanumeric, upperAlphanumeric, lowerAlphanumeric, alphanumericSpace, upperAlphanumericSpace, lowerAlphanumericSpace, int, positiveInt, negativeInt, strictInt, strictPositiveInt, strictNegativeInt, float, positiveFloat, negativeFloat, strictFloat, money, positiveMoney, negativeMoney, accountingMoney, negativeAccountingMoney| null |
4678
| `preventInvalidInput` | When enabled, invalid keystrokes are ignored (the value of the text field is not updated). When disabled, invalid keystrokes are not ignored. | boolean | true/false | true |
79+
| `logger` | An optional callback function for logging. If you want to enable logging, provide a function and then do whatever you wish with the message. | function | A function accepting the log message as a string argument | undefined |
4780

4881

4982
## Events
@@ -54,7 +87,7 @@ These events are fired based on the state of the text field.
5487
| ------------------| ----------------------------------------------------------------|
5588
| inputIgnored | Fires when an invalid keystroke is ignored. `preventInvalidInput` must be enabled for this event to fire. |
5689
| validationFailed | Fires when an invalid keystroke is made when `preventInvalidInput` is disabled. Also fires if validation performed on blur() fails. |
57-
| validationSuccess | Fires when the user removes invalid data when `preventInvalidInput` is disabled. Also fires if validation performed on blur() passes. |
90+
| validationSuccess | Fires when the user removes invalid data when `preventInvalidInput` is disabled. Also fires if validation performed on blur() succeeds. |
5891

5992

6093
#### Example
@@ -69,20 +102,57 @@ $( "#field" ).restrictedTextField( {
69102
} );
70103
```
71104

72-
See the included HTML file for a complete demo.
105+
See `demo/demo.html` for complete examples.
106+
73107

108+
# Desktop Browser Compatibility
74109

75-
# Browser Compatibility
110+
This plugin has only been tested on desktop browsers. Mobile testing might happen in the future. As for desktop browsers, many other versions of Firefox and Chrome, whether older or newer than what's listed here, are certainly compatible. Browsers not listed here might work fine, but have not been tested.
76111

77-
* Firefox 45.0.1: Compatible
78-
* Chrome 49.0.2623.108 m: Compatible
112+
* Firefox 49.0.2: Compatible
113+
* Chrome 54.0.2840.99 m: Compatible
79114
* Edge: Compatible
80115
* IE 11: Compatible
81116
* IE 10: Compatible
82117
* IE 9: Compatible
83118
* IE 8: INCOMPATIBLE
84119

85120

121+
# Running the Unit Tests
122+
123+
[Selenium](http://www.seleniumhq.org) is used for unit testing in order to generate true keypresses in a text field. A JavaScript-based framework (such as QUnit, etc.) would have made life simpler, but synthetic JavaScript events don't carry out the actual actions associated with them. In other words, simulating a keypress fires the correct events, but doesn't result in actual text being written to a text field. This is a security restriction of JavaScript. As a result, this project uses Selenium and JUnit.
124+
125+
1. Install the following build dependencies:
126+
* [Node.js](https://nodejs.org/en)
127+
* [Gradle](http://gradle.org)
128+
* [Java JDK](http://www.oracle.com/technetwork/java/javase/index.html) version 8 or later
129+
* [BuildScripts](https://github.com/kloverde/BuildScripts)
130+
2. Modify the `buildScriptsDir` property in `SeleniumTester/gradle.properties` to reflect the location of BuildScripts on your filesystem
131+
3. Download the appropriate browser drivers for your system at [seleniumhq.org](http://www.seleniumhq.org). Once you've downloaded them, update `geckoDriverPath`, `edgeDriverPath`, `ieDriverPath` and `chromeDriverPath` in `SeleniumTester/gradle.properties` with their paths.
132+
4. If you're testing in IE, set Protected Mode to the same value in all zones (it doesn't matter whether it's set to enabled or disabled, just that it's the same for all). See [here](http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html) for more information. If that page disappears from the Web, see [the Wayback Machine's copy](http://web.archive.org/web/20151026094711/http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html).
133+
5. Set your browsers' zoom levels to 100%. If you don't, Selenium will throw an exception, at least for IE.
134+
6. Update the `browsers` property in `SeleniumTester/gradle.properties` to reflect which browsers you'll be testing with. This is explained further by documentation found in the properties file.
135+
7. Now, from a command prompt:
136+
1. `cd` to the project root (`jquery-RestrictedTextField`)
137+
2. Type `npm install`
138+
3. Type `npm test`
139+
140+
141+
#### UNIT TESTS GOTCHAS:
142+
143+
* #### The Selenium project's 64-bit IE driver is broken for IE 10 and 11, and according to a Selenium contributor, is unfixable. See [here](https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5116) and [here](http://jimevansmusic.blogspot.com/2014/09/screenshots-sendkeys-and-sixty-four.html). If you're testing on a 64-bit version of Windows with IE 10 or 11, use the 32-bit driver instead. Its performance is still quite poor, but is far better than the 64-bit driver.
144+
145+
* #### If you're using Windows and if you haven't used Selenium before, Windows Firewall will pop up an alert asking whether to allow driver servers to listen for connections. You need to grant these permissions. During this time, one or more of the unit tests will fail. Simply re-run the tests after the permission has been granted.
146+
147+
* #### If you're running the unit tests in Firefox, you must use Firefox 48 or later. Starting with Firefox 48, Selenium is required to use the Marionette/Gecko driver, and my code is written to initialize that particular driver. Although RestrictedTextField itself is supported on older Firefox releases, the unit tests are not.
148+
149+
* #### If you're running the unit tests in Firefox, the last known Gecko driver which worked was v0.10.0. Sometime after that, something happened in the Gecko driver which messes up the tests' ability to trigger blur events, which results in practically every test failing. Version 0.11.1 (November, 2016) is confirmed to cause this problem. No later version of the Gecko driver has been tested.
150+
151+
* #### It's critical that you do not interact with the machine in any way while tests are running. Being that this plugin is event-driven, any action that could cause an event to be fired unexpectedly could cause tests to fail. This includes human actions, but also includes applications popping up notifications or asserting themselves in other ways. To the extent possible, you should take steps to minimize this possibility.
152+
153+
* #### The tests fail in Edge if Edge doesn't have focus. Sometimes Edge opens behind another window (for example, the console which you might have used to invoke the tests).
154+
155+
86156
## Thanks
87157

88-
Do you like this library? Want to toss a few bucks my way to say thanks? I accept donations at https://paypal.me/KurtisLoVerde/5. Thank you for your support!
158+
Do you like this software? Want to toss a few bucks my way to say thanks? I accept donations at https://paypal.me/KurtisLoVerde/10. Thank you for your support!

SeleniumTester/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apply plugin: "eclipse" // Run 'gradle eclipse' to rebuild .classpath for other systems
2+
3+
apply from: buildScriptsDir + "/build_java_lib.gradle"
4+
5+
6+
dependencies {
7+
testCompile "junit:junit:4.12"
8+
testCompile "org.seleniumhq.selenium:selenium-server:3.0.1"
9+
}
10+
11+
test {
12+
// Uncomment these lines if the tests fail to run. They're commented
13+
// by default to avoid being drowned in Marionette/Gecko messages.
14+
//testLogging.showStandardStreams = true;
15+
//logging.captureStandardOutput LogLevel.INFO
16+
17+
exclude "**/*Test.class"
18+
include "**/SeleniumTestSuite.class"
19+
}

0 commit comments

Comments
 (0)