dialtone_rails 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/LICENSE +21 -0
- data/README.md +171 -0
- data/lib/dialtone_rails/form_builder.rb +18 -0
- data/lib/dialtone_rails/version.rb +3 -0
- data/lib/dialtone_rails.rb +13 -0
- metadata +84 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 79eb721d3fcb6710c389165928dbd3a79c663955fb80e94820e95844f503f5c0
|
|
4
|
+
data.tar.gz: ab6ad1cd95a740cb5d9a46eff88e0306a820ca9102a43375f9efbebf36d724ea
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fafd6fb010948ed5e6f192a06a8ad905a852ae1ebae44241f76843fc501e50ba5a5a77f97ec31eed391ae121cc8652bc0962dae3d16051ead21fc4798e569885
|
|
7
|
+
data.tar.gz: 4926f5f13543c29c316b432d67b8dcd354af1631a7e5ee6b69cd36e1f4a7fc2083ec5bd8312f1cb4593833a9083c65719687053428168e376e15f6c09eb76b49
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Harun
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Dialtone Rails
|
|
2
|
+
|
|
3
|
+
A small Rails wrapper around [intl-tel-input](https://github.com/jackocnr/intl-tel-input)
|
|
4
|
+
for international phone fields with a country picker and number formatting.
|
|
5
|
+
|
|
6
|
+
The Ruby gem is **`dialtone_rails`**; its companion npm package is **`dialtone-rails`**.
|
|
7
|
+
|
|
8
|
+
```erb
|
|
9
|
+
<%= form.intl_tel_field :phone_number,
|
|
10
|
+
initial_country: "ba",
|
|
11
|
+
class_names: {
|
|
12
|
+
input: "input",
|
|
13
|
+
container: "w-full",
|
|
14
|
+
country_selector: "rounded-lg shadow-lg",
|
|
15
|
+
search_input: "input"
|
|
16
|
+
} %>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Add to your Gemfile:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem "dialtone_rails"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Install the Ruby and JavaScript packages:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
bundle install
|
|
31
|
+
npm install dialtone-rails
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The npm package includes intl-tel-input and its formatting utilities.
|
|
35
|
+
|
|
36
|
+
Register the controller once with your existing Stimulus application:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import DialtoneController from "dialtone-rails"
|
|
40
|
+
|
|
41
|
+
application.register("dialtone", DialtoneController)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Import the stylesheet in your bundler-managed CSS **before your application's
|
|
45
|
+
layer declarations**, including Tailwind's imports:
|
|
46
|
+
|
|
47
|
+
```css
|
|
48
|
+
@import "dialtone-rails/styles";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Your bundler must support the stylesheet's `.webp` flag images. Vite handles these
|
|
52
|
+
automatically; with esbuild, add `--loader:.webp=file` to your build command.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
Use it with standard Rails forms and labels:
|
|
57
|
+
|
|
58
|
+
```erb
|
|
59
|
+
<%= form_with model: @contact do |form| %>
|
|
60
|
+
<%= form.label :phone_number %>
|
|
61
|
+
<%= form.intl_tel_field :phone_number,
|
|
62
|
+
initial_country: "ba",
|
|
63
|
+
required: true,
|
|
64
|
+
autocomplete: "tel",
|
|
65
|
+
class_names: { input: "input", container: "w-full" } %>
|
|
66
|
+
<%= form.submit %>
|
|
67
|
+
<% end %>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
- `initial_country:` is an ISO two-letter country code. By default no country is
|
|
73
|
+
assumed. An existing international number determines its own country.
|
|
74
|
+
- `class_names:` is the single place to specify classes, including the input's
|
|
75
|
+
classes. Slot names use snake_case and map directly to upstream `classNames`.
|
|
76
|
+
- `options:` accepts JSON-compatible [upstream options](https://intl-tel-input.com/docs/options).
|
|
77
|
+
Use snake_case keys, including in nested hashes.
|
|
78
|
+
- Remaining arguments are ordinary input attributes: `id:`, `value:`, `style:`,
|
|
79
|
+
`required:`, `disabled:`, `readonly:`, `autocomplete:`, `data:`, and `aria:`.
|
|
80
|
+
|
|
81
|
+
For example:
|
|
82
|
+
|
|
83
|
+
```erb
|
|
84
|
+
<%= form.intl_tel_field :phone_number,
|
|
85
|
+
initial_country: "ba",
|
|
86
|
+
options: {
|
|
87
|
+
only_countries: %w[ba hr rs me],
|
|
88
|
+
separate_dial_code: false,
|
|
89
|
+
country_name_locale: "bs",
|
|
90
|
+
ui_translations: { search_placeholder: "Pretraži" }
|
|
91
|
+
} %>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`country_name_locale` translates country names. Use `ui_translations` for search
|
|
95
|
+
text and other interface strings; unspecified strings remain in English.
|
|
96
|
+
|
|
97
|
+
Options that require JavaScript callbacks or DOM elements cannot be passed from
|
|
98
|
+
Ruby. Leave `hidden_inputs` and `load_utils` unset; submission and formatting are
|
|
99
|
+
already provided.
|
|
100
|
+
|
|
101
|
+
## Styling
|
|
102
|
+
|
|
103
|
+
Omitting `class_names:` uses upstream's neutral appearance. There is no Tailwind,
|
|
104
|
+
Bootstrap, or application-specific theme dependency.
|
|
105
|
+
|
|
106
|
+
Add classes through `class_names:`. Available slots include `input`, `container`,
|
|
107
|
+
`selected_country`, `country_selector`, `search_input`, and `country_list_item`.
|
|
108
|
+
See the [full list of styling slots](https://intl-tel-input.com/docs/theming).
|
|
109
|
+
|
|
110
|
+
Normal unlayered application CSS overrides the gem's layered CSS. With layered
|
|
111
|
+
styles, declare the `intl-tel-input` layer before your application layers. If your
|
|
112
|
+
build assembles CSS from several entrypoints, explicitly declare the order first:
|
|
113
|
+
|
|
114
|
+
```css
|
|
115
|
+
@layer intl-tel-input, theme, base, components, utilities;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
CSS variables work too:
|
|
119
|
+
|
|
120
|
+
```css
|
|
121
|
+
.my-phone-field {
|
|
122
|
+
--iti-border-color: #ccc;
|
|
123
|
+
--iti-country-selector-bg: white;
|
|
124
|
+
--iti-hover-color: #f3f4f6;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Apply that class with `class_names: { container: "my-phone-field" }`. Use upstream
|
|
129
|
+
sizing options and CSS variables for widget positioning and input padding.
|
|
130
|
+
|
|
131
|
+
## Submitted values
|
|
132
|
+
|
|
133
|
+
The form submits the full international number under the original Rails field
|
|
134
|
+
name, e.g. `contact[phone_number] = "+38761123456"`, while the input displays a
|
|
135
|
+
readable, formatted number.
|
|
136
|
+
|
|
137
|
+
- Empty fields submit an empty string; disabled fields are omitted.
|
|
138
|
+
- Formatting is not validation. Incomplete numbers are not rejected, and values
|
|
139
|
+
that cannot be formatted are preserved. Validate phone numbers in your Rails model.
|
|
140
|
+
- `strict_mode` restricts typed characters by default. Disable it with
|
|
141
|
+
`options: { strict_mode: false }`.
|
|
142
|
+
- Use distinct names or indexed `fields_for` names for multiple inputs. Repeated
|
|
143
|
+
names such as `phones[]` are unsupported.
|
|
144
|
+
- Submitted numbers use E.164 format; extensions require separate handling.
|
|
145
|
+
|
|
146
|
+
Native forms, Turbo submissions, form resets, and fields added through Turbo
|
|
147
|
+
Frames or Streams are supported. Back navigation preserves the number and country.
|
|
148
|
+
|
|
149
|
+
Without JavaScript, the helper remains a normal `type="tel"` input and submits its
|
|
150
|
+
raw value. If you serialize forms manually, use `FormData`; reading `.value` reads
|
|
151
|
+
the displayed value, not necessarily the full international number.
|
|
152
|
+
|
|
153
|
+
## Run the demo
|
|
154
|
+
|
|
155
|
+
From this repository:
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
bundle install
|
|
159
|
+
npm install
|
|
160
|
+
npm run build:demo
|
|
161
|
+
bundle exec rackup demo/config.ru --port 3001
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Open <http://localhost:3001>. Try six phone fields with different formatting,
|
|
165
|
+
country, and language settings. Each field's info icon shows its configuration;
|
|
166
|
+
the reference below the form explains all options. Submit to see the values
|
|
167
|
+
received by Rails.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
MIT licensed. intl-tel-input and Stimulus retain their own licenses.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module DialtoneRails
|
|
2
|
+
module FormBuilder
|
|
3
|
+
def intl_tel_field(method, initial_country: "", class_names: {}, options: {}, **html_options)
|
|
4
|
+
classes = class_names.transform_keys { |key| key.to_s.camelize(:lower) }
|
|
5
|
+
configuration = options.deep_transform_keys { |key| key.to_s.camelize(:lower) }
|
|
6
|
+
.merge("initialCountry" => initial_country.to_s.downcase, "classNames" => classes)
|
|
7
|
+
|
|
8
|
+
data = (html_options[:data] || {}).merge("dialtone-target" => "input")
|
|
9
|
+
input = telephone_field(method, html_options.merge(class: classes["input"], data: data))
|
|
10
|
+
|
|
11
|
+
@template.tag.div(input, data: {
|
|
12
|
+
controller: "dialtone",
|
|
13
|
+
action: "turbo:before-cache@document->dialtone#disconnect turbo:render@document->dialtone#connect",
|
|
14
|
+
"dialtone-options-value" => configuration
|
|
15
|
+
})
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "rails/railtie"
|
|
2
|
+
require_relative "dialtone_rails/version"
|
|
3
|
+
require_relative "dialtone_rails/form_builder"
|
|
4
|
+
|
|
5
|
+
module DialtoneRails
|
|
6
|
+
class Railtie < Rails::Railtie
|
|
7
|
+
initializer "dialtone_rails.form_builder" do
|
|
8
|
+
ActiveSupport.on_load(:action_view) do
|
|
9
|
+
ActionView::Helpers::FormBuilder.include DialtoneRails::FormBuilder
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dialtone_rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Harun
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-09-24 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: actionview
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '9'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '8.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '9'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: railties
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '8.0'
|
|
39
|
+
- - "<"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '9'
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '8.0'
|
|
49
|
+
- - "<"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '9'
|
|
52
|
+
executables: []
|
|
53
|
+
extensions: []
|
|
54
|
+
extra_rdoc_files: []
|
|
55
|
+
files:
|
|
56
|
+
- LICENSE
|
|
57
|
+
- README.md
|
|
58
|
+
- lib/dialtone_rails.rb
|
|
59
|
+
- lib/dialtone_rails/form_builder.rb
|
|
60
|
+
- lib/dialtone_rails/version.rb
|
|
61
|
+
homepage: https://github.com/sabljak/dialtone_rails
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
source_code_uri: https://github.com/sabljak/dialtone_rails
|
|
66
|
+
bug_tracker_uri: https://github.com/sabljak/dialtone_rails/issues
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
require_paths:
|
|
69
|
+
- lib
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.2'
|
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
requirements: []
|
|
81
|
+
rubygems_version: 3.6.2
|
|
82
|
+
specification_version: 4
|
|
83
|
+
summary: Rails form helper for intl-tel-input
|
|
84
|
+
test_files: []
|