simple_client_validation 0.1.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
+ SHA1:
3
+ metadata.gz: 4427a580b45929fa08797a3c02e2103c7d6900d1
4
+ data.tar.gz: eb810a914ffc356b8e8d9c10c9e28633aa22450a
5
+ SHA512:
6
+ metadata.gz: 508bf3457d46b265cfc11c2b1663e4a17ad239d7710afaaf2aa4378fa1ec6beb7b0eec42ae14324cd2b04f37cb1ef6c7da35b743f3c562439fa4571127965cd6
7
+ data.tar.gz: 8cba09fc5a56965eb2733c9e39c512542e7d4c0eaa6575442634006a75a91287c387f6a70fe329fd0d60ad8586545597eab57fef59288390370b48b79d658da8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_client_validation.gemspec
4
+ gemspec
5
+
6
+ gem "font-awesome-rails"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Petar Risteski
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,75 @@
1
+ # SimpleClientValidation
2
+
3
+ This is a simple client validation i.e. with given messages the user will get simple notice about the input fields.
4
+ This gem is build for the simple_form, so please make sure to add this line to your application's Gemfile:
5
+ ```ruby
6
+ gem 'simple_form'
7
+ ```
8
+ and check the documentation for the installation instructions:
9
+ [simple_form](https://github.com/plataformatec/simple_form)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'simple_client_validation'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ ## Usage
24
+
25
+ Because this gem uses font-awesome, make sure to add this line in your `application.css` if you haven't already
26
+
27
+ ```css
28
+ /*
29
+ *= require font-awesome
30
+ */
31
+ ```
32
+ and after that add the simple_client_validation styles
33
+ ```css
34
+ /*
35
+ *= require simple_client_validation
36
+ */
37
+ ```
38
+ Require simple_client_validation Javascripts in `application.js`:
39
+
40
+ ```js
41
+ //= require simple_client_validation
42
+ ```
43
+ Then restart your webserver if it was previously running.
44
+
45
+ Because this gem is built for
46
+ ```ruby
47
+ gem 'simple_form'
48
+ ```
49
+ to add custom error messages for the input field you need to add:
50
+ ```ruby
51
+ input_html: { message: "Your message here" }
52
+ ```
53
+ and it should look like this:
54
+ ```ruby
55
+ f.input :email, label: 'Email', input_html: { message: "Your message here" }
56
+ ```
57
+ or if you use I18n gem
58
+ ```ruby
59
+ f.input :email, label: t('Email'), input_html: { message: t("YourMessageHere") }
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bobpetar/simple_client_validation.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_client_validation"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module SimpleClientValidation
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "simple_client_validation/version"
2
+
3
+ module SimpleClientValidation
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_client_validation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_client_validation"
8
+ spec.version = SimpleClientValidation::VERSION
9
+ spec.authors = ["Petar Risteski"]
10
+ spec.email = ["risteskipetar3@gmail.com"]
11
+
12
+ spec.summary = %q{Simple client validation messages}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/bobpetar/simple_client_validation"
15
+ spec.license = "MIT"
16
+
17
+
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,98 @@
1
+ $(document).on("turbolinks:load", function(){
2
+ var selectedInput = null;
3
+ $(function() {
4
+ // for more inputs use $('input, select, textarea')
5
+ $('input, select, textarea').focus(function() {
6
+ selectedInput = this;
7
+ }).blur(function(){
8
+ if (selectedInput.value == "") {
9
+ // if the input is empty but already has an error message
10
+ try {
11
+ var id_to_remove = "added-error" + selectedInput.id;
12
+ document.getElementById(id_to_remove).remove();
13
+ } catch (e) {
14
+ console.log("Continue ...");
15
+ }
16
+ // if input is empty -> get the error message
17
+ try {
18
+ var error_message = selectedInput.getAttribute("message");
19
+ } catch (e) {
20
+ console.log("Continue ...");
21
+ }
22
+
23
+ if (error_message != null) {
24
+ // add error message if given
25
+ var element_id = selectedInput.id;
26
+ var el = document.createElement("span");
27
+ el.innerHTML = '<i class="fa fa-times" aria-hidden="true"></i>' + " " + error_message;
28
+ el.id = "added-error" + element_id;
29
+ el.className += " scv-error-message"
30
+ var div = document.getElementById(element_id);
31
+ insertAfter(div, el);
32
+ }
33
+ }else {
34
+ // if input is not empty -> remove error message if any
35
+ try {
36
+ var id_to_remove = "added-error" + selectedInput.id;
37
+ document.getElementById(id_to_remove).remove();
38
+ } catch (e) {
39
+ console.log("Continue ...");
40
+ }
41
+
42
+ // check if valid Email if the input type is email
43
+ if(selectedInput.type == "email"){
44
+ var get_value = selectedInput.value; // get the email address
45
+ var atpos = get_value.indexOf("@");
46
+ var dotpos = get_value.lastIndexOf(".");
47
+ // check if the email address is valid
48
+ if (atpos<1 || dotpos<atpos+2 || dotpos+2>=get_value.length) {
49
+ var error_message = "Not a valid e-mail address";
50
+ var element_id = selectedInput.id;
51
+ var el = document.createElement("span");
52
+ el.innerHTML = '<i class="fa fa-times" aria-hidden="true"></i>' + " " + error_message;
53
+ el.id = "added-error" + element_id;
54
+ el.className += " scv-error-message"
55
+ var div = document.getElementById(element_id);
56
+ insertAfter(div, el);
57
+ }else{
58
+ // if the email is valid -> remove the error message if any
59
+ try {
60
+ var id_to_remove = "added-error" + selectedInput.id;
61
+ document.getElementById(id_to_remove).remove();
62
+ } catch (e) {
63
+ console.log("Continue ...");
64
+ }
65
+ }
66
+ }
67
+ // check if the input is password and its length
68
+ if(selectedInput.type == "password"){
69
+ if (selectedInput.value.length < 6) {
70
+ var error_message = "Password must be at least 6 characters";
71
+ var element_id = selectedInput.id;
72
+ var el = document.createElement("span");
73
+ el.innerHTML = '<i class="fa fa-times" aria-hidden="true"></i>' + " " + error_message;
74
+ el.id = "added-error" + element_id;
75
+ el.className += " scv-error-message"
76
+ var div = document.getElementById(element_id);
77
+ insertAfter(div, el);
78
+ }else{
79
+ // if the email is valid -> remove the error message if any
80
+ try {
81
+ var id_to_remove = "added-error" + selectedInput.id;
82
+ document.getElementById(id_to_remove).remove();
83
+ } catch (e) {
84
+ console.log("Continue ...");
85
+ }
86
+ }
87
+ }
88
+ }
89
+ // forget the input element
90
+ selectedInput = null;
91
+
92
+ });
93
+ });
94
+ // add error message after input
95
+ function insertAfter(referenceNode, newNode) {
96
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
97
+ }
98
+ });
@@ -0,0 +1,3 @@
1
+ .scv-error-message{
2
+ color: #dd5959;
3
+ }
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_client_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Petar Risteski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-07 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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
+ description: ''
42
+ email:
43
+ - risteskipetar3@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/simple_client_validation.rb
56
+ - lib/simple_client_validation/version.rb
57
+ - simple_client_validation.gemspec
58
+ - vendor/assets/javascripts/simple_client_validation.js
59
+ - vendor/assets/stylesheets/simple_client_validation.css
60
+ homepage: https://github.com/bobpetar/simple_client_validation
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.11
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Simple client validation messages
84
+ test_files: []