uix_validations 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +13 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +2 -0
- data/{vendor → app}/assets/javascripts/uix_validations.js +0 -0
- data/{vendor → app}/assets/stylesheets/uix_validations.scss +0 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/uix_validations.rb +6 -0
- data/lib/uix_validations/engine.rb +4 -0
- data/lib/uix_validations/version.rb +3 -0
- data/uix_validations.gemspec +38 -0
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38bd0d741cc6a00414d96b740f3a7f6240a1804fa14386dcb52e788552af17e4
|
4
|
+
data.tar.gz: da6fc6e640daaa73cee647916eece8fd25e59de232c0847bd68b82f5f2126a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa08fd1a4f873e3e70bdd0e2e5b59aeb1578fe723b4664315e42129bc942ad07662616d7be3db2b1528212d8e9ed11deec54d579ecdd117e9ae5b4103ab0a56
|
7
|
+
data.tar.gz: e4ebad797a8e6f1d4fee52dd220592fd547fbe10427c0cc116bceed74b48be95f8dd0216c7c99066689ec8f4e3ce06f9ee0e05004b2cb752e76079746dfcb414
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 lucasandrad
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# UixValidations
|
2
|
+
|
3
|
+
`uix_validations` is a gem that provides Js functions for real time validations.
|
4
|
+
|
5
|
+
Uix is the abbreviation that I "created" for UI and UX, since this gem has some things from both worlds
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'uix_validations'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
bundle install
|
18
|
+
|
19
|
+
|
20
|
+
Than in your Rails project add this line at `app/assets/javascripts/application.js`
|
21
|
+
|
22
|
+
```
|
23
|
+
//= require uix_validations
|
24
|
+
```
|
25
|
+
|
26
|
+
And this import at `app/assets/stylesheets/application.scss`
|
27
|
+
|
28
|
+
```scss
|
29
|
+
@import "uix_validations";
|
30
|
+
```
|
31
|
+
|
32
|
+
If you are using `application.css` insted of `application.scss`, you can import uix_validations into any `.scss` file.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Live demo
|
37
|
+
Check out this live demo using Uix Validations: [uix_validations_demo link here](https://uix-validations-demo.herokuapp.com/)
|
38
|
+
|
39
|
+
### Examples
|
40
|
+
Real time validation for numbers:
|
41
|
+
```html
|
42
|
+
<!-- html -->
|
43
|
+
<div class="input">
|
44
|
+
<%= f.label 'Validation Number' %><br>
|
45
|
+
<%= f.text_field :title, class: 'input-text', id: 'input-num' %>
|
46
|
+
<!-- Add this div under your input -->
|
47
|
+
<div class="uix-validation" id="vali1">
|
48
|
+
Should have only numbers
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
<script>
|
53
|
+
// pass your input Id and your div Id
|
54
|
+
validateNumber("#input-num", "#vali1");
|
55
|
+
</script>
|
56
|
+
```
|
57
|
+
---
|
58
|
+
Real time validation for characters
|
59
|
+
```html
|
60
|
+
<div class="input">
|
61
|
+
<%= f.label 'Validation Character' %><br>
|
62
|
+
<%= f.text_field :title, class: 'input-text', id: 'input-char' %>
|
63
|
+
<div class="uix-validation" id="vali2">
|
64
|
+
Should have only characters
|
65
|
+
</div>
|
66
|
+
</div>
|
67
|
+
|
68
|
+
<script>
|
69
|
+
validateCharacter("#input-char", "#vali2");
|
70
|
+
</script>
|
71
|
+
```
|
72
|
+
---
|
73
|
+
Real time validation for characters with length 5 - 10
|
74
|
+
```html
|
75
|
+
<script>
|
76
|
+
validateCharacterLength("#input-num", "#vali1", [5,10]);
|
77
|
+
</script>
|
78
|
+
```
|
79
|
+
|
80
|
+
### Table with all functions
|
81
|
+
|
82
|
+
| Js Function | What is it for? |
|
83
|
+
|---|---|
|
84
|
+
| `validateNumber(input_id, div_id)` | Valid if there are only numbers |
|
85
|
+
| `validateNumberRange(input_id, div_id, [0, 2])` | For now validates only the length of the number, example: [0,2] it's 00 to 99 |
|
86
|
+
| `validateCharacter(input_id, div_id)` | Valid if there are only Characters |
|
87
|
+
| `validateCharacterLength(input_id, div_id, [0, 2])` | Valid if there are only Characters with the correct length |
|
88
|
+
| `validateNonDigit(input_id, div_id)` | Valid if there is anything except digits |
|
89
|
+
| `validateNonDigitLength(input_id, div_id, [0, 2])` | Valid if there is anything except digits with the correct length |
|
90
|
+
| `validateJustLength(input_id, div_id, [0,2])` | Valid if the value has the correct length |
|
91
|
+
| `validateEmail(input_id, div_id)` | Checks for a valid email |
|
92
|
+
| `validateRegex(input_id, div_id, custom_regex)` | Validate a custom regex |
|
93
|
+
| `validateStrongPassword(input_id, div_id)` | Validate if the password has: at least one digit, at least one character and at least 8 characters |
|
94
|
+
| `validateVeryStrongPassword(input_id, div_id)` | Validate if the password has: at least one digit, at least one upcase character, at least one downcase character and at least 8 characters |
|
95
|
+
|
96
|
+
### Customize
|
97
|
+
You can customize the style of the div with the validation message<br>
|
98
|
+
Here is the flow of the validation:<br>
|
99
|
+
- When the page loads, the class of validation div is: `class="uix-validation"`
|
100
|
+
- When the user is typing the class change to: `class="uix-validation uix-default"`
|
101
|
+
- If the input.value is valid the div class change to: `class="uix-validation uix-valid"`
|
102
|
+
- If the input.value is invalid, when user click out of the input the class change to: `class="uix-validation uix-invalid"`
|
103
|
+
|
104
|
+
So if the `.uix-valid` and `.uix-invalid` styles are not exactly what you want, you can change the style as you want.
|
105
|
+
|
106
|
+
## Good practices about real time validations
|
107
|
+
This gem is inspired in [Luke Wroblewski study, (article here)](https://alistapart.com/article/inline-validation-in-web-forms) about validation in web forms. This article was published in 2009 but it's still a excellent reference about form validations. Many writers use Luke study as reference in other articles [Example here](https://designmodo.com/ux-form-validation/)
|
108
|
+
|
109
|
+
**This gem follow this practices:**
|
110
|
+
- Show the validation at the right time (right after the user has submitted the input value)
|
111
|
+
- Show the validation at the right place (under the input)
|
112
|
+
- Correct colors (not too red and not too green)
|
113
|
+
- The colors change at the right moment (while the user types validations don't turn red, only if he click outside the input, but if the input value is valid the validations turn green, because is good to know that the value is correct just in time)
|
114
|
+
- Validations don't have a alarming design (I am not a design but I tried to make then clean and understandable, something like the ideas of minimalist design)
|
115
|
+
|
116
|
+
## Write good messages
|
117
|
+
|
118
|
+
Good messages can be a differential in your forms. Don't scare your users with alarming messages, like:<br>**Error: this is wrong. Use just numbers**<br>
|
119
|
+
|
120
|
+
Instead you need to focus in what is wrong and help the user to fix it. Something like:<br>
|
121
|
+
**Should have onlye numbers. Ex: 99887766**
|
122
|
+
|
123
|
+
You can read more about it here: [UX Movement, post about good messages](http://uxmovement.com/forms/how-to-make-your-form-error-messages-more-reassuring/)
|
124
|
+
|
125
|
+
|
126
|
+
## Contributing
|
127
|
+
|
128
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lucasandrad/uix_validations.
|
129
|
+
|
130
|
+
## License
|
131
|
+
|
132
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
File without changes
|
File without changes
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "uix_validations"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "uix_validations/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "uix_validations"
|
8
|
+
spec.version = UixValidations::VERSION
|
9
|
+
spec.authors = ["Lucas Andrade"]
|
10
|
+
spec.email = ["lucasandrad@yandex.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem provides real time validations for forms}
|
13
|
+
spec.description = %q{This gem provides real time validations for forms. All validations follow the best principles of UI and UX}
|
14
|
+
spec.homepage = "https://github.com/LucasAndrad/uix_validations"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_runtime_dependency 'autoprefixer-rails', '~> 9.1', '>= 9.1.0'
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uix_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Andrade
|
@@ -66,8 +66,19 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
-
-
|
70
|
-
-
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- app/assets/javascripts/uix_validations.js
|
75
|
+
- app/assets/stylesheets/uix_validations.scss
|
76
|
+
- bin/console
|
77
|
+
- bin/setup
|
78
|
+
- lib/uix_validations.rb
|
79
|
+
- lib/uix_validations/engine.rb
|
80
|
+
- lib/uix_validations/version.rb
|
81
|
+
- uix_validations.gemspec
|
71
82
|
homepage: https://github.com/LucasAndrad/uix_validations
|
72
83
|
licenses:
|
73
84
|
- MIT
|