formstrap 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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +33 -0
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +28 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +10 -0
- data/app/assets/config/headmin_manifest.js +2 -0
- data/app/assets/images/avatar.jpg +0 -0
- data/app/assets/images/document.docx +0 -0
- data/app/assets/images/document.pdf +0 -0
- data/app/assets/images/image.jpg +0 -0
- data/app/assets/images/spreadsheet.xls +0 -0
- data/app/assets/images/video.mp4 +0 -0
- data/app/assets/javascripts/formstrap/config/i18n.js +11 -0
- data/app/assets/javascripts/formstrap/controllers/autocomplete_controller.js +318 -0
- data/app/assets/javascripts/formstrap/controllers/date_range_controller.js +38 -0
- data/app/assets/javascripts/formstrap/controllers/dropzone_controller.js +31 -0
- data/app/assets/javascripts/formstrap/controllers/file_preview_controller.js +244 -0
- data/app/assets/javascripts/formstrap/controllers/flatpickr_controller.js +35 -0
- data/app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js +28 -0
- data/app/assets/javascripts/formstrap/controllers/media_controller.js +252 -0
- data/app/assets/javascripts/formstrap/controllers/media_modal_controller.js +147 -0
- data/app/assets/javascripts/formstrap/controllers/redactorx_controller.js +40 -0
- data/app/assets/javascripts/formstrap/controllers/repeater_controller.js +148 -0
- data/app/assets/javascripts/formstrap/controllers/select_controller.js +49 -0
- data/app/assets/javascripts/formstrap/controllers/textarea_controller.js +48 -0
- data/app/assets/javascripts/formstrap/index.js +32 -0
- data/app/assets/javascripts/formstrap.js +11515 -0
- data/app/assets/stylesheets/formstrap/forms/autocomplete.scss +27 -0
- data/app/assets/stylesheets/formstrap/forms/file.scss +83 -0
- data/app/assets/stylesheets/formstrap/forms/media.scss +10 -0
- data/app/assets/stylesheets/formstrap/forms/repeater.scss +62 -0
- data/app/assets/stylesheets/formstrap/forms/search.scss +12 -0
- data/app/assets/stylesheets/formstrap/forms.scss +12 -0
- data/app/assets/stylesheets/formstrap/general.scss +18 -0
- data/app/assets/stylesheets/formstrap/media/index.scss +9 -0
- data/app/assets/stylesheets/formstrap/media.scss +1 -0
- data/app/assets/stylesheets/formstrap/utilities/buttons.scss +27 -0
- data/app/assets/stylesheets/formstrap/utilities/dropzone.scss +72 -0
- data/app/assets/stylesheets/formstrap/utilities.scss +2 -0
- data/app/assets/stylesheets/formstrap/vendor/flatpickr.css +903 -0
- data/app/assets/stylesheets/formstrap/vendor/tom-select-bootstrap.scss +535 -0
- data/app/assets/stylesheets/formstrap.css +1559 -0
- data/app/assets/stylesheets/formstrap.scss +11 -0
- data/app/controllers/concerns/formstrap/pagination.rb +27 -0
- data/app/controllers/formstrap/media_controller.rb +68 -0
- data/app/controllers/formstrap_controller.rb +2 -0
- data/app/models/concerns/formstrap/autocompletable.rb +36 -0
- data/app/models/concerns/formstrap/hintable.rb +22 -0
- data/app/models/concerns/formstrap/input_groupable.rb +21 -0
- data/app/models/concerns/formstrap/labelable.rb +31 -0
- data/app/models/concerns/formstrap/listable.rb +26 -0
- data/app/models/concerns/formstrap/placeholderable.rb +11 -0
- data/app/models/concerns/formstrap/validatable.rb +38 -0
- data/app/models/concerns/formstrap/wrappable.rb +19 -0
- data/app/models/formstrap/.DS_Store +0 -0
- data/app/models/formstrap/association_view.rb +100 -0
- data/app/models/formstrap/blocks_view.rb +43 -0
- data/app/models/formstrap/checkbox_view.rb +50 -0
- data/app/models/formstrap/color_view.rb +45 -0
- data/app/models/formstrap/date_range_view.rb +23 -0
- data/app/models/formstrap/date_view.rb +43 -0
- data/app/models/formstrap/datetime_range_view.rb +23 -0
- data/app/models/formstrap/datetime_view.rb +43 -0
- data/app/models/formstrap/email_view.rb +46 -0
- data/app/models/formstrap/file_view.rb +106 -0
- data/app/models/formstrap/flatpickr_range_view.rb +89 -0
- data/app/models/formstrap/flatpickr_view.rb +27 -0
- data/app/models/formstrap/hidden_view.rb +8 -0
- data/app/models/formstrap/hint_view.rb +4 -0
- data/app/models/formstrap/input_group_view.rb +17 -0
- data/app/models/formstrap/label_view.rb +22 -0
- data/app/models/formstrap/media_item_view.rb +41 -0
- data/app/models/formstrap/media_view.rb +143 -0
- data/app/models/formstrap/number_view.rb +47 -0
- data/app/models/formstrap/password_view.rb +42 -0
- data/app/models/formstrap/redactorx_view.rb +57 -0
- data/app/models/formstrap/search_view.rb +46 -0
- data/app/models/formstrap/select_view.rb +61 -0
- data/app/models/formstrap/switch_view.rb +21 -0
- data/app/models/formstrap/text_view.rb +46 -0
- data/app/models/formstrap/textarea_view.rb +47 -0
- data/app/models/formstrap/url_view.rb +46 -0
- data/app/models/formstrap/wrapper_view.rb +17 -0
- data/app/models/formstrap/wysiwyg_view.rb +15 -0
- data/app/models/view_model.rb +62 -0
- data/app/views/formstrap/_association.html.erb +30 -0
- data/app/views/formstrap/_autocomplete.html.erb +11 -0
- data/app/views/formstrap/_blocks.html.erb +45 -0
- data/app/views/formstrap/_checkbox.html.erb +34 -0
- data/app/views/formstrap/_color.html.erb +32 -0
- data/app/views/formstrap/_datalist.html.erb +3 -0
- data/app/views/formstrap/_date.html.erb +41 -0
- data/app/views/formstrap/_date_range.html.erb +40 -0
- data/app/views/formstrap/_datetime.html.erb +41 -0
- data/app/views/formstrap/_datetime_range.html.erb +40 -0
- data/app/views/formstrap/_email.html.erb +43 -0
- data/app/views/formstrap/_errors.html.erb +19 -0
- data/app/views/formstrap/_file.html.erb +94 -0
- data/app/views/formstrap/_flatpickr.html.erb +33 -0
- data/app/views/formstrap/_flatpickr_range.html.erb +40 -0
- data/app/views/formstrap/_hidden.html.erb +23 -0
- data/app/views/formstrap/_hint.html.erb +21 -0
- data/app/views/formstrap/_input_group.html.erb +21 -0
- data/app/views/formstrap/_label.html.erb +22 -0
- data/app/views/formstrap/_media.html.erb +60 -0
- data/app/views/formstrap/_number.html.erb +41 -0
- data/app/views/formstrap/_password.html.erb +39 -0
- data/app/views/formstrap/_redactorx.html.erb +31 -0
- data/app/views/formstrap/_repeater.html.erb +128 -0
- data/app/views/formstrap/_search.html.erb +43 -0
- data/app/views/formstrap/_select.html.erb +43 -0
- data/app/views/formstrap/_switch.html.erb +29 -0
- data/app/views/formstrap/_text.html.erb +42 -0
- data/app/views/formstrap/_textarea.html.erb +39 -0
- data/app/views/formstrap/_to_ary.html.erb +0 -0
- data/app/views/formstrap/_url.html.erb +43 -0
- data/app/views/formstrap/_validation.html.erb +18 -0
- data/app/views/formstrap/_wrapper.html.erb +8 -0
- data/app/views/formstrap/_wysiwyg.html.erb +28 -0
- data/app/views/formstrap/autocomplete/_item.html.erb +3 -0
- data/app/views/formstrap/autocomplete/_list.html.erb +3 -0
- data/app/views/formstrap/blocks/_modal.html.erb +20 -0
- data/app/views/formstrap/fields/_base.html.erb +25 -0
- data/app/views/formstrap/fields/_file.html.erb +17 -0
- data/app/views/formstrap/fields/_files.html.erb +17 -0
- data/app/views/formstrap/fields/_group.html.erb +52 -0
- data/app/views/formstrap/fields/_list.html.erb +31 -0
- data/app/views/formstrap/fields/_text.html.erb +17 -0
- data/app/views/formstrap/media/_item.html.erb +38 -0
- data/app/views/formstrap/media/_media_item_modal.html.erb +77 -0
- data/app/views/formstrap/media/_modal.html.erb +40 -0
- data/app/views/formstrap/media/_thumbnail.html.erb +20 -0
- data/app/views/formstrap/media/_validation.html.erb +10 -0
- data/app/views/formstrap/media/create.turbo_stream.erb +5 -0
- data/app/views/formstrap/media/index.html.erb +3 -0
- data/app/views/formstrap/media/index.turbo_stream.erb +11 -0
- data/app/views/formstrap/media/show.html.erb +9 -0
- data/app/views/formstrap/media/thumbnail.html.erb +3 -0
- data/app/views/formstrap/media/update.turbo_stream.erb +3 -0
- data/app/views/formstrap/pagination/_infinite.html.erb +7 -0
- data/app/views/formstrap/repeater/_row.html.erb +53 -0
- data/app/views/formstrap/shared/_notifications.html.erb +20 -0
- data/app/views/formstrap/shared/_popup.html.erb +32 -0
- data/app/views/formstrap/shared/_thumbnail.html.erb +35 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/importmap.rb +2 -0
- data/config/locales/activerecord/en.yml +12 -0
- data/config/locales/activerecord/nl.yml +13 -0
- data/config/locales/defaults/en.yml +215 -0
- data/config/locales/defaults/nl.yml +213 -0
- data/config/locales/devise/en.yml +65 -0
- data/config/locales/devise/nl.yml +85 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/formstrap/forms/en.yml +39 -0
- data/config/locales/formstrap/forms/nl.yml +39 -0
- data/config/locales/formstrap/media/en.yml +24 -0
- data/config/locales/formstrap/media/nl.yml +24 -0
- data/config/locales/formstrap/thumbnail/en.yml +4 -0
- data/config/locales/formstrap/thumbnail/nl.yml +4 -0
- data/config/locales/nl.yml +6 -0
- data/config/routes.rb +11 -0
- data/esbuild-css.js +25 -0
- data/esbuild-js.js +11 -0
- data/formstrap.gemspec +37 -0
- data/formstrap.iml +34 -0
- data/lib/formstrap/engine.rb +27 -0
- data/lib/formstrap/form_builder.rb +177 -0
- data/lib/formstrap/form_helper.rb +19 -0
- data/lib/formstrap/version.rb +3 -0
- data/lib/formstrap.rb +6 -0
- data/package.json +54 -0
- data/src/js/formstrap.js +1 -0
- data/src/scss/formstrap.scss +1 -0
- data/yarn.lock +1998 -0
- metadata +224 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef711395960778d13a1deabebd22b2745d05b3f23cead8088c0213e051fca436
|
4
|
+
data.tar.gz: 14080e33cab4d2f4403188d0fac4c097a8ca1a5179465bf83eb0cc42c951161f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79982ab77ff7cf658c946d0d4a8f574af5b1c6a95aad44ec746a48fde13341fe82fb9ea4f77e664324868a2671a2b37ea3d9aacc08d13ae24cb1cbd710e7a4cd
|
7
|
+
data.tar.gz: d400b9aa96761a49ad6cf07736e876110c4d5360ade1337888b4c86dbac3cb981254118dedb0a13cc4aa3d66951c7a1fb9630be1fbe42826dd0cbc0b185f03cc
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
/node_modules/
|
10
|
+
|
11
|
+
# Ignore dummy app
|
12
|
+
/test/dummy/log/*
|
13
|
+
/test/dummy/tmp/*
|
14
|
+
/test/dummy/db/*.sqlite3
|
15
|
+
/test/dummy/db/*.sqlite3-*
|
16
|
+
!/test/dummy/log/.keep
|
17
|
+
!/test/dummy/tmp/.keep
|
18
|
+
/test/dummy/tmp/pids/*
|
19
|
+
!/test/dummy/tmp/pids/
|
20
|
+
!/test/dummy/tmp/pids/.keep
|
21
|
+
/test/dummy/storage/*
|
22
|
+
!/test/dummy/storage/.keep
|
23
|
+
/test/dummy/public/assets
|
24
|
+
|
25
|
+
# Ingore editors
|
26
|
+
/.idea
|
27
|
+
/headmin.iml
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Formstap Changelog
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at vlamingsjef@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in formstrap.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "capybara", ">= 3.26"
|
7
|
+
gem "minitest", "~> 5.0"
|
8
|
+
gem "minitest-spec-rails", "~> 6.1"
|
9
|
+
gem "puma", "~> 5.2"
|
10
|
+
gem "rails", "~> 7.0"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "sprockets-rails", "~> 3.4"
|
13
|
+
gem "sqlite3", "~> 1.4"
|
14
|
+
gem "standard", "~> 1.7"
|
15
|
+
gem "debug"
|
16
|
+
|
17
|
+
# Dummy app
|
18
|
+
gem "devise", "~> 4.8"
|
19
|
+
gem "enumerize", "~> 2.3"
|
20
|
+
gem "sassc-rails", "~> 2.1"
|
21
|
+
gem "image_processing", "~> 1.2"
|
22
|
+
gem "inline_svg", "~> 1.7"
|
23
|
+
gem "kaminari", "~> 1.2"
|
24
|
+
gem "route_translator", "~> 12.0"
|
25
|
+
gem "acts_as_list", "~> 1.0"
|
26
|
+
gem "breadcrumbs_on_rails", "~> 4.1"
|
27
|
+
gem "importmap-rails", "~> 1.0"
|
28
|
+
gem "hotwire-rails", "~> 0.1"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jef Vlamings
|
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,118 @@
|
|
1
|
+
# Formstrap
|
2
|
+
|
3
|
+
An extensive Bootstrap form library to power your Ruby On Rails application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's gemfile ```./Gemfile```
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem 'formstrap'
|
11
|
+
```
|
12
|
+
|
13
|
+
Afterwards, run:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Getting started
|
22
|
+
|
23
|
+
Use the Formstrap helpers ```formstrap_form_for``` or ```formstrap_form_with``` instead of the Ruby on Rails helpers
|
24
|
+
```form_for``` or ```form_with```.
|
25
|
+
|
26
|
+
An example:
|
27
|
+
|
28
|
+
```erb
|
29
|
+
<%= formstrap_form_for(@user) do |f| %>
|
30
|
+
<%= f.email :email, required: true %>
|
31
|
+
<%= f.password :password, required: true %>
|
32
|
+
<%= f.checkbox :remember_me, required: true %>
|
33
|
+
<%= f.submit "Log In" %>
|
34
|
+
<% end %>
|
35
|
+
```
|
36
|
+
|
37
|
+
As you might have noticed, Formstrap uses different named form helpers than Ruby on Rails.
|
38
|
+
|
39
|
+
If the original Rails helper needs to be accessed, it can be accessed by:
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<%= formstrap_for_for(@user) do |f| %>
|
43
|
+
<%= f.text :name, formstrap: false %>
|
44
|
+
<%= f.text_field :name %>
|
45
|
+
<% end %>
|
46
|
+
```
|
47
|
+
|
48
|
+
An overview of all the Formstrap / Ruby on Rails form helpers:
|
49
|
+
|
50
|
+
| Type | Formstrap helpers | Ruby on Rails helpers |
|
51
|
+
|-------------------|-------------------|---------------------------------------------|
|
52
|
+
| Association | association | N/A |
|
53
|
+
| Checkbox | checkbox | checkbox formstrap: false or check_box |
|
54
|
+
| Color | color | color formstrap: false or color_field |
|
55
|
+
| Date | date | date formstrap: false or date_field |
|
56
|
+
| Date range | date_range | N/A |
|
57
|
+
| Datetime | datetime | datetime formstrap: false or datetime_field |
|
58
|
+
| Datetime range | datetime_range | N/A |
|
59
|
+
| Email | email | email formstrap: false or email_field |
|
60
|
+
| File | file | file formstrap: false or file_field |
|
61
|
+
| Flatpickr * | flatpickr | N/A |
|
62
|
+
| Flatpickr range * | flatpickr_range | N/A |
|
63
|
+
| Hidden | hidden | hidden formstrap: false or hidden_field |
|
64
|
+
| Media | media | N/A |
|
65
|
+
| Number | number | number formstrap: false or number_field |
|
66
|
+
| Password | password | password formstrap: false or password_field |
|
67
|
+
| RedactorX * | redactorx | N/A |
|
68
|
+
| Search | search | N/A |
|
69
|
+
| Select | select | select formstrap: false |
|
70
|
+
| Switch | switch | N/A |
|
71
|
+
| Text | text | text formstrap: false or text_field |
|
72
|
+
| Textarea | textarea | textarea formstrap: false or text_area |
|
73
|
+
| URL | url | url formstrap: false or url_field |
|
74
|
+
| WYSIWYG * | wysiwyg | N/A |
|
75
|
+
|
76
|
+
\* Formstrap provides the implementation of these 3rd party libraries, however it is up to the user to provide the
|
77
|
+
correct assets.
|
78
|
+
|
79
|
+
As you might have noticed, Formstrap provides more helpers than what is standard in Ruby on Rails, e.g. ```Media```, ```Date range```, ```RedactorX``` ...
|
80
|
+
|
81
|
+
### Altering Formstrap helpers
|
82
|
+
|
83
|
+
Because Formstrap uses html and Ruby on Rails helpers behind the scenes to render its helpers, editing the Formstrap
|
84
|
+
helpers is straightforward.
|
85
|
+
|
86
|
+
As Formstrap is an engine, its views are within the gem. In order to have a copy of the views inside your application,
|
87
|
+
run:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
rails generate formstrap:views
|
91
|
+
```
|
92
|
+
|
93
|
+
This will create a directory ```./views/formstrap```, in which all the views (and its helpers) are copied in and can thus be
|
94
|
+
inspected / altered. Because Formstrap is an engine, the application's local files take precedence over the engine's files.
|
95
|
+
|
96
|
+
Note that on new releases, one can once more run:
|
97
|
+
|
98
|
+
```bash
|
99
|
+
rails generate formstrap:views
|
100
|
+
```
|
101
|
+
|
102
|
+
To get new or updated versions of the helpers. **This will override the files that are already present (and which might contain your personal adjustments)**.
|
103
|
+
|
104
|
+
### Extending Formstrap helpers
|
105
|
+
|
106
|
+
Extending Formstrap helpers is straightforward.
|
107
|
+
|
108
|
+
Add your custom Formstrap (e.g. map) helper into the map ```./views/formstrap```. Formstrap makes it possible to access this helper is by its filename.
|
109
|
+
|
110
|
+
|
111
|
+
```erb
|
112
|
+
<%# custom Formstrap helper file: ./views/formstrap/_map.html.erb %>
|
113
|
+
|
114
|
+
<%= formstrap_form_for(@user) do |f| %>
|
115
|
+
<%= f.map :address %>
|
116
|
+
<% end %>
|
117
|
+
```
|
118
|
+
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,318 @@
|
|
1
|
+
/* global fetch, Event */
|
2
|
+
import { Controller } from '@hotwired/stimulus'
|
3
|
+
|
4
|
+
export default class extends Controller {
|
5
|
+
static get targets () {
|
6
|
+
return ['input', 'dropdown', 'dropdownItem']
|
7
|
+
}
|
8
|
+
|
9
|
+
static get values () {
|
10
|
+
return {
|
11
|
+
url: String
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
connect () {
|
16
|
+
// Focus
|
17
|
+
this.inputTarget.addEventListener('focus', (event) => {
|
18
|
+
this.show()
|
19
|
+
})
|
20
|
+
|
21
|
+
// Navigation
|
22
|
+
this.inputTarget.addEventListener('keydown', (event) => {
|
23
|
+
this.handleKeydown(event)
|
24
|
+
})
|
25
|
+
|
26
|
+
// Typing
|
27
|
+
this.inputTarget.addEventListener('keyup', (event) => {
|
28
|
+
this.handleKeyup(event)
|
29
|
+
})
|
30
|
+
|
31
|
+
// Clicked outside dropdown
|
32
|
+
document.addEventListener('click', (event) => {
|
33
|
+
this.handleOutsideClick(event)
|
34
|
+
})
|
35
|
+
}
|
36
|
+
|
37
|
+
handleKeydown (event) {
|
38
|
+
const keyCode = parseInt(event.keyCode, 10)
|
39
|
+
if (this.isArrowKey(keyCode)) {
|
40
|
+
this.handleArrowKey(keyCode)
|
41
|
+
}
|
42
|
+
|
43
|
+
if (this.isEnterKey(keyCode)) {
|
44
|
+
this.selectActiveItem(event)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
handleKeyup (event) {
|
49
|
+
// Ignore arrow keys or enters
|
50
|
+
const keyCode = parseInt(event.keyCode, 10)
|
51
|
+
if (this.isArrowKey(keyCode) || this.isEnterKey(keyCode)) {
|
52
|
+
return false
|
53
|
+
}
|
54
|
+
|
55
|
+
this.handleTextKey()
|
56
|
+
}
|
57
|
+
|
58
|
+
selectActiveItem (event) {
|
59
|
+
const activeItem = this.activeItem()
|
60
|
+
if (activeItem) {
|
61
|
+
this.deselectAll()
|
62
|
+
this.setValue(activeItem.getAttribute('value'))
|
63
|
+
event.preventDefault()
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
isEnterKey (keyCode) {
|
68
|
+
return keyCode === 13
|
69
|
+
}
|
70
|
+
|
71
|
+
handleArrowKey (keyCode) {
|
72
|
+
this.show()
|
73
|
+
switch (keyCode) {
|
74
|
+
case 38:
|
75
|
+
this.handleArrowUp()
|
76
|
+
break
|
77
|
+
case 40:
|
78
|
+
this.handleArrowDown()
|
79
|
+
break
|
80
|
+
default:
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
handleArrowUp () {
|
85
|
+
this.selectPreviousItem()
|
86
|
+
}
|
87
|
+
|
88
|
+
handleArrowDown () {
|
89
|
+
this.selectNextItem()
|
90
|
+
}
|
91
|
+
|
92
|
+
selectNextItem () {
|
93
|
+
const next = this.nextItem()
|
94
|
+
if (next) {
|
95
|
+
this.deselectAll()
|
96
|
+
next.classList.add('active')
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
nextItem () {
|
101
|
+
const current = this.activeItem()
|
102
|
+
|
103
|
+
// Select first item if nothing selected
|
104
|
+
if (!this.hasSelectedItem()) {
|
105
|
+
return this.firstItem()
|
106
|
+
}
|
107
|
+
|
108
|
+
if (this.isItemLast(current)) {
|
109
|
+
return this.firstItem()
|
110
|
+
} else {
|
111
|
+
const index = this.itemIndex(current)
|
112
|
+
return this.itemAtIndex(index + 1)
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
selectPreviousItem () {
|
117
|
+
const previous = this.previousItem()
|
118
|
+
if (previous) {
|
119
|
+
this.deselectAll()
|
120
|
+
previous.classList.add('active')
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
previousItem () {
|
125
|
+
const current = this.activeItem()
|
126
|
+
|
127
|
+
// Select last item if nothing selected
|
128
|
+
if (!this.hasSelectedItem()) {
|
129
|
+
return this.lastItem()
|
130
|
+
}
|
131
|
+
|
132
|
+
if (this.isItemFirst(current)) {
|
133
|
+
return this.lastItem()
|
134
|
+
} else {
|
135
|
+
const index = this.itemIndex(current)
|
136
|
+
return this.itemAtIndex(index - 1)
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
deselectAll () {
|
141
|
+
this.dropdownItemTargets.forEach(dropdownItem => {
|
142
|
+
dropdownItem.classList.remove('active')
|
143
|
+
})
|
144
|
+
}
|
145
|
+
|
146
|
+
itemAtIndex (index) {
|
147
|
+
return this.dropdownItemTargets[index]
|
148
|
+
}
|
149
|
+
|
150
|
+
firstItem () {
|
151
|
+
return this.itemAtIndex(0)
|
152
|
+
}
|
153
|
+
|
154
|
+
lastItem () {
|
155
|
+
return this.itemAtIndex(this.dropdownItemTargets.length - 1)
|
156
|
+
}
|
157
|
+
|
158
|
+
hasSelectedItem () {
|
159
|
+
return this.activeItem() !== undefined
|
160
|
+
}
|
161
|
+
|
162
|
+
activeItem () {
|
163
|
+
return this.dropdownItemTargets.find((item) => {
|
164
|
+
return item.classList.contains('active')
|
165
|
+
})
|
166
|
+
}
|
167
|
+
|
168
|
+
isItemLast (item) {
|
169
|
+
return this.itemIndex(item) === this.dropdownItemTargets.length - 1
|
170
|
+
}
|
171
|
+
|
172
|
+
isItemFirst (item) {
|
173
|
+
return this.itemIndex(item) === 0
|
174
|
+
}
|
175
|
+
|
176
|
+
itemIndex (item) {
|
177
|
+
return Array.from(this.dropdownItemTargets).indexOf(item)
|
178
|
+
}
|
179
|
+
|
180
|
+
handleTextKey () {
|
181
|
+
// 1. fetch info
|
182
|
+
this.fetchCollection().then((html) => {
|
183
|
+
// 2. render html
|
184
|
+
this.renderCollection(html)
|
185
|
+
}).then(() => {
|
186
|
+
// 3. Highlight
|
187
|
+
this.highlight()
|
188
|
+
}).then(() => {
|
189
|
+
// 4. Preselect first result
|
190
|
+
this.activateFirstItem()
|
191
|
+
}).then(() => {
|
192
|
+
// 5. Show results
|
193
|
+
this.show()
|
194
|
+
})
|
195
|
+
}
|
196
|
+
|
197
|
+
activateFirstItem () {
|
198
|
+
this.deselectAll()
|
199
|
+
this.firstItem().classList.add('active')
|
200
|
+
}
|
201
|
+
|
202
|
+
show () {
|
203
|
+
if (this.isDropdownEmpty()) {
|
204
|
+
this.dropdownTarget.classList.remove('d-none')
|
205
|
+
} else {
|
206
|
+
this.hide()
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
hide () {
|
211
|
+
this.dropdownTarget.classList.add('d-none')
|
212
|
+
}
|
213
|
+
|
214
|
+
isDropdownEmpty () {
|
215
|
+
return this.dropdownTarget.textContent.trim().length > 0
|
216
|
+
}
|
217
|
+
|
218
|
+
isArrowKey (keyCode) {
|
219
|
+
const arrowKeyCodes = [37, 38, 39, 40]
|
220
|
+
return arrowKeyCodes.includes(keyCode)
|
221
|
+
}
|
222
|
+
|
223
|
+
fetchCollection () {
|
224
|
+
if (this.isRemote()) {
|
225
|
+
return fetch(this.remoteURL()).then((response) => {
|
226
|
+
return response.text()
|
227
|
+
}).catch((error) => {
|
228
|
+
console.error('The URL you provided for the autocomplete collection didn\'t return a successful result', error)
|
229
|
+
})
|
230
|
+
} else {
|
231
|
+
return Promise.resolve(this.dropdownTarget.innerHTML)
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
remoteURL () {
|
236
|
+
// Set dummy base in case a relative path is provided as remote URL
|
237
|
+
const base = 'https://example.com'
|
238
|
+
const url = new URL(this.urlValue, base)
|
239
|
+
|
240
|
+
// Update pagination params
|
241
|
+
const params = new URLSearchParams(url.search)
|
242
|
+
params.set('search', this.value())
|
243
|
+
params.set('page', '1')
|
244
|
+
params.set('per_page', '6')
|
245
|
+
url.search = params.toString()
|
246
|
+
|
247
|
+
// Convert to string
|
248
|
+
let urlString = url.toString()
|
249
|
+
|
250
|
+
// Convert back to relative url if needed
|
251
|
+
if (urlString.includes(base)) {
|
252
|
+
urlString = urlString.replace(base, '')
|
253
|
+
}
|
254
|
+
|
255
|
+
return urlString
|
256
|
+
}
|
257
|
+
|
258
|
+
renderCollection (html) {
|
259
|
+
this.dropdownTarget.innerHTML = html
|
260
|
+
}
|
261
|
+
|
262
|
+
isRemote () {
|
263
|
+
return this.hasUrlValue
|
264
|
+
}
|
265
|
+
|
266
|
+
highlight () {
|
267
|
+
const query = this.value()
|
268
|
+
this.dropdownItemTargets.forEach(dropdownItem => {
|
269
|
+
let text = dropdownItem.innerHTML
|
270
|
+
|
271
|
+
// Clean up past results
|
272
|
+
text = text.replace(/<mark.*?>(.*?)<\/mark>/ig, '$1')
|
273
|
+
|
274
|
+
// Highlight query
|
275
|
+
if (query && query.length > 0) {
|
276
|
+
// Ignore all strings inside < >
|
277
|
+
const regex2 = new RegExp(`(?<!<[^>]*?)( )?(${query})`, 'gi')
|
278
|
+
text = text.replace(regex2, '<mark>$2</mark>')
|
279
|
+
}
|
280
|
+
|
281
|
+
dropdownItem.innerHTML = text
|
282
|
+
})
|
283
|
+
}
|
284
|
+
|
285
|
+
select (event) {
|
286
|
+
this.setValue(event.currentTarget.getAttribute('value'))
|
287
|
+
}
|
288
|
+
|
289
|
+
setValue (value) {
|
290
|
+
this.inputTarget.value = value
|
291
|
+
this.inputTarget.dispatchEvent(new Event('change'))
|
292
|
+
this.hide()
|
293
|
+
}
|
294
|
+
|
295
|
+
value () {
|
296
|
+
return this.inputTarget.value
|
297
|
+
}
|
298
|
+
|
299
|
+
numberOfCharacters () {
|
300
|
+
return this.value().length
|
301
|
+
}
|
302
|
+
|
303
|
+
handleOutsideClick (event) {
|
304
|
+
if (!this.isClickedInside(event)) {
|
305
|
+
this.hide()
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
isClickedInside (event) {
|
310
|
+
if (!event) {
|
311
|
+
return false
|
312
|
+
}
|
313
|
+
const inInput = this.inputTarget.contains(event.target)
|
314
|
+
const inDropdown = this.dropdownTarget.contains(event.target)
|
315
|
+
|
316
|
+
return (inInput || inDropdown)
|
317
|
+
}
|
318
|
+
}
|