form-reflex 1.0.1 → 1.0.2
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 +4 -4
- data/README.md +88 -79
- data/lib/form/reflex/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c516a5bb445f353b3ce0770dafec83837a702557c54ab6bddeae36b07752d35
|
4
|
+
data.tar.gz: 523c4553f61ce8b4441eb53105ff3d362cbbcf953e9460f8aa1bdd1d9505069c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '018f36b9318804533d55cbdb4deec9e74f92d4bfdfded2cdc04f4b22832df40e67be99e48e8a392d83c27030fd710e23a9910e15df0911e4a559bac8bcd482e0'
|
7
|
+
data.tar.gz: 3e6fba3ab58c5224f4174dc2dfc4ce357fe2febd2c3b2bc57ba75db88218cb0c1b0331f385165e0078c9a4a32ba829ed12f2e2ada278494fff505d0bc8707d64
|
data/README.md
CHANGED
@@ -1,79 +1,88 @@
|
|
1
|
-
# FormReflex
|
2
|
-
FormReflex is a light extension of [optimism](https://optimism.leastbad.com/), leveraging [stimulus_reflex](https://docs.stimulusreflex.com/).
|
3
|
-
|
4
|
-
FormReflex provides real time form validation on change, using the validations already provided on your model.
|
5
|
-
|
6
|
-
## Usage
|
7
|
-
|
8
|
-
Please follow the setup instructions for optimism [here](https://optimism.leastbad.com/quick-start)
|
9
|
-
|
10
|
-
Usage for FormReflex is *identical* to the optimism usage, with 2 exceptions:
|
11
|
-
|
12
|
-
1) You must specify data-reflex="change->FormReflex#handle_change" on your form control
|
13
|
-
|
14
|
-
```erb
|
15
|
-
data-reflex="change->FormReflex#handle_change"
|
16
|
-
```
|
17
|
-
|
18
|
-
2) The model you want to validate must be initialized in session[:model]
|
19
|
-
|
20
|
-
For example:
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
def new
|
24
|
-
@post = Post.new
|
25
|
-
session[:model] = @post unless @stimulus_reflex
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
def set_post
|
30
|
-
@post = Post.find(params[:id])
|
31
|
-
session[:model] = @post unless @stimulus_reflex
|
32
|
-
end
|
33
|
-
```
|
34
|
-
|
35
|
-
All in all, pulling in [Optimism's](https://optimism.leastbad.com/) own example, it would look like this:
|
36
|
-
|
37
|
-
```erb
|
38
|
-
<%= form_with(model: session[:model]) do |form| %>
|
39
|
-
<div class="field">
|
40
|
-
<%= form.label :name %>
|
41
|
-
<%= form.text_field :name, data: { reflex: "change->
|
42
|
-
<%= form.error_for :name %>
|
43
|
-
</div>
|
44
|
-
|
45
|
-
<div class="field">
|
46
|
-
<%= form.label :body %>
|
47
|
-
<%= form.text_area :body, data: { reflex: "change->
|
48
|
-
<%= form.error_for :body %>
|
49
|
-
</div>
|
50
|
-
|
51
|
-
<div class="actions">
|
52
|
-
<%= form.submit %>
|
53
|
-
</div>
|
54
|
-
<% end %>
|
55
|
-
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
1
|
+
# FormReflex
|
2
|
+
FormReflex is a light extension of [optimism](https://optimism.leastbad.com/), leveraging [stimulus_reflex](https://docs.stimulusreflex.com/).
|
3
|
+
|
4
|
+
FormReflex provides real time form validation on change, using the validations already provided on your model.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Please follow the setup instructions for optimism [here](https://optimism.leastbad.com/quick-start)
|
9
|
+
|
10
|
+
Usage for FormReflex is *identical* to the optimism usage, with 2 exceptions:
|
11
|
+
|
12
|
+
1) You must specify data-reflex="change->FormReflex#handle_change" on your form control
|
13
|
+
|
14
|
+
```erb
|
15
|
+
data-reflex="change->FormReflex#handle_change"
|
16
|
+
```
|
17
|
+
|
18
|
+
2) The model you want to validate must be initialized in session[:model]
|
19
|
+
|
20
|
+
For example:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
def new
|
24
|
+
@post = Post.new
|
25
|
+
session[:model] = @post unless @stimulus_reflex
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def set_post
|
30
|
+
@post = Post.find(params[:id])
|
31
|
+
session[:model] = @post unless @stimulus_reflex
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
All in all, pulling in [Optimism's](https://optimism.leastbad.com/) own example, it would look like this:
|
36
|
+
|
37
|
+
```erb
|
38
|
+
<%= form_with(model: session[:model]) do |form| %>
|
39
|
+
<div class="field">
|
40
|
+
<%= form.label :name %>
|
41
|
+
<%= form.text_field :name, data: { reflex: "change->FormReflex#handle_change" } %>
|
42
|
+
<%= form.error_for :name %>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div class="field">
|
46
|
+
<%= form.label :body %>
|
47
|
+
<%= form.text_area :body, data: { reflex: "change->FormReflex#handle_change" } %>
|
48
|
+
<%= form.error_for :body %>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div class="actions">
|
52
|
+
<%= form.submit %>
|
53
|
+
</div>
|
54
|
+
<% end %>
|
55
|
+
```
|
56
|
+
|
57
|
+
You can also add models to an association easily with the `add` method. There's a corresponding `delete` method for removing models from
|
58
|
+
an association. Simply add `data-assocation="<name of association>" data-reflex="click->FormReflex#add"`
|
59
|
+
|
60
|
+
```
|
61
|
+
<button type="button" data-association="post_details" data-reflex="click->FormReflex#add">
|
62
|
+
Add Post Detail
|
63
|
+
</button>
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
## Installation
|
68
|
+
Add this line to your application's Gemfile:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
gem 'form-reflex'
|
72
|
+
```
|
73
|
+
|
74
|
+
And then execute:
|
75
|
+
```bash
|
76
|
+
$ bundle
|
77
|
+
```
|
78
|
+
|
79
|
+
Or install it yourself as:
|
80
|
+
```bash
|
81
|
+
$ gem install form-reflex
|
82
|
+
```
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
Contribution directions go here.
|
86
|
+
|
87
|
+
## License
|
88
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/form/reflex/version.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: form-reflex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua LeBlanc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.3
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: '5.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 6.0.3
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
29
|
+
version: '5.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: optimism
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|