uix_validations 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15824261a4c36c4df25da78eb1df0ffc2c570def6c9039b0e90888e8eea8b7dd
4
+ data.tar.gz: 76b77a37b13e33ef76b6fd074f017b38d847a20e08bb9a41e61d7d0b6358cd3d
5
+ SHA512:
6
+ metadata.gz: eafaf2c7a7a73e6a0d6705963ca9dde233b3c9de7b066103e675cde3dce238167ded6e7edf7d4a89d37440173620707aff90aa65b11e09fdd5af5bde3c0ec05f
7
+ data.tar.gz: 24b035c648e9f9b5fa402c646d1053b21c2a34e4130e0a4690958dffd7534dbe953a63e141047e269c665752adc67fb1f1583fa034d6f918d11bf84b5b11f848
@@ -0,0 +1,106 @@
1
+ // Regex list
2
+ var numberPattern = /^[0-9]*$/;
3
+ var characterPattern = /^[a-zA-Z]*$/;
4
+ var nonDigitPattern = /^[^0-9]*$/;
5
+
6
+ // From https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
7
+ var emailPattern = /\S+@\S+\.\S+/;
8
+
9
+ // From https://stackoverflow.com/questions/14850553/javascript-regex-for-password-containing-at-least-8-characters-1-number-1-uppe
10
+ var strongPasswordPattern = /^(?=.*\d)[0-9a-zA-Z]{8,}$/;
11
+
12
+ var veryStrongPasswordPattern = /^(?=.*[A-Z])(?=.*[!@#$&*.,_-])(?=.*[0-9])(?=.*[a-z]).{8,}$/
13
+
14
+ // Flow
15
+ // onClick -> set default
16
+ // checkinputValue->
17
+ // if (while is typing value is valid) { SET VALID }
18
+ // else { SET default }
19
+ // checkinputout->
20
+ // if (onFocusOut is valid) { SET VALID }
21
+ // else { SET INVALID }
22
+
23
+ // Generic functions
24
+ function validatePattern(fieldId, validId, regex) {
25
+ var field = document.querySelector(fieldId);
26
+ field.addEventListener("click", () => {
27
+ var valid = document.querySelector(validId);
28
+ setDefaultClass(valid);
29
+ checkInputValue(field, valid, regex)
30
+ checkInputOut(field, valid, regex);
31
+ });
32
+ }
33
+ function checkInputValue(field, valid, regex) {
34
+ field.addEventListener("keyup", () => {
35
+ switchClasses(field, valid, regex, ['uix-defaulf', 'uix-valid']);
36
+ // find way to get class type
37
+ });
38
+ }
39
+ function checkInputOut(field, valid, regex) {
40
+ field.addEventListener("focusout", () => {
41
+ switchClasses(field, valid, regex);
42
+ // find way to get class type
43
+ });
44
+ }
45
+ function setClasses(element, classIn) {
46
+ element.className = 'uix-validation ' + classIn;
47
+ }
48
+ function setDefaultClass(element) {
49
+ element.className = 'uix-validation uix-default';
50
+ element.style.visibility = 'inherit';
51
+ }
52
+ function switchClasses(field, valid, regex, classes = ['uix-invalid', 'uix-valid']) {
53
+ if(regex.test(field.value) && field.value != '') {
54
+ setClasses(valid, classes[1]);
55
+ }
56
+ else {
57
+ setClasses(valid, classes[0]);
58
+ }
59
+ }
60
+
61
+ // Specific functions
62
+ // Number
63
+ function validateNumber(fieldId, validId) {
64
+ validatePattern(fieldId, validId, numberPattern);
65
+ }
66
+ function validateNumberRange(fieldId, validId, range=[0,10]) {
67
+ var numberRangePattern = new RegExp(`^\\d{`+range[0]+`,`+range[1]+`}$`);
68
+ validatePattern(fieldId, validId, numberRangePattern);
69
+ }
70
+ // Character
71
+ function validateCharacter(fieldId, validId) {
72
+ validatePattern(fieldId, validId, characterPattern);
73
+ }
74
+ function validateCharacterLength(fieldId, validId, range=[0,10]) {
75
+ var characterRangePattern = new RegExp(`^\[a-zA-Z]{`+range[0]+`,`+range[1]+`}$`);
76
+ validatePattern(fieldId, validId, characterRangePattern);
77
+ }
78
+ // Non digit
79
+ function validateNonDigit(fieldId, validId) {
80
+ validatePattern(fieldId, validId, nonDigitPattern);
81
+ }
82
+ function validateNonDigitLength(fieldId, validId, range=[0,10]) {
83
+ var nonDigitRangePattern = new RegExp(`^\\D{`+range[0]+`,`+range[1]+`}$`);
84
+ validatePattern(fieldId, validId, nonDigitRangePattern);
85
+ }
86
+ // Email
87
+ function validateEmail(fieldId, validId) {
88
+ validatePattern(fieldId, validId, emailPattern);
89
+ }
90
+ // Range
91
+ function validateJustLength(fieldId, validId, range=[0,10]) {
92
+ var rangePattern = new RegExp(`^\\S{`+range[0]+`,`+range[1]+`}$`);
93
+ validatePattern(fieldId, validId, rangePattern);
94
+ }
95
+ // Any regex
96
+ function validateRegex(fieldId, validId, regex) {
97
+ validatePattern(fieldId, validId, regex);
98
+ }
99
+ // Strong Password
100
+ function validateStrongPassword(fieldId, validId) {
101
+ validatePattern(fieldId, validId, strongPasswordPattern);
102
+ }
103
+ // Very Strong Password
104
+ function validateVeryStrongPassword(fieldId, validId) {
105
+ validatePattern(fieldId, validId, veryStrongPasswordPattern);
106
+ }
@@ -0,0 +1,23 @@
1
+ .uix-validation {
2
+ padding: 1%;
3
+ font-size: 90%;
4
+ color: #232323;
5
+ width: 100%;
6
+ visibility: hidden;
7
+ }
8
+ .uix-default {
9
+ background: #ffffff;
10
+ }
11
+ .uix-valid {
12
+ color: #04a100;
13
+ font-weight: 400;
14
+ // background: #64e066;
15
+
16
+ }
17
+ .uix-invalid {
18
+ color: #cf0a0a;
19
+ font-weight: 400;
20
+ // background: #ff8484;
21
+ }
22
+
23
+ // old #5bff5e
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uix_validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Andrade
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: autoprefixer-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '9.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 9.1.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '9.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 9.1.0
61
+ description: This gem provides real time validations for forms. All validations follow
62
+ the best principles of UI and UX
63
+ email:
64
+ - lucasandrad@yandex.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - assets/javascripts/uix_validations.js
70
+ - assets/stylesheets/uix_validations.scss
71
+ homepage: https://github.com/LucasAndrad
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.7.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: This gem provides real time validations for forms
95
+ test_files: []