web47core 1.1.9 → 1.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d053924ad96678d323142bb50866aa6524667d2f1ec8d7fdec674b62bff0476e
4
- data.tar.gz: eb5648235bb6b68e5d40dc387c6d3656edff6b45cef2841709cfa977a83fe31f
3
+ metadata.gz: c95dc1ded2406eed714fa60226d939f995826d8fdb4997e86a967f4363a0dcfd
4
+ data.tar.gz: fe198b4505c6a33fa455af240b59f28bcc1a38e3da9da3a9b77879dfbeeb56a3
5
5
  SHA512:
6
- metadata.gz: d9262faca8080174f19ec9b67de0e3c9a1efd2edf87db623521d8cbadd421619068d0d968a8f5abe93bf15ad1e48d415b8d632f2d86fb11c16631056c92c01e8
7
- data.tar.gz: '088f8e45fa0765124468b117a9652942452bbcb2499dba51d20675962a52ff18c8f7f4b0040607b5074267f7f431c401faf8c32937c85c803a057ea12c9d539f'
6
+ metadata.gz: 6849efd0b1fc1c5960251d23ce8777738864c1e460e3e5832b64b06c733a858e2c408eefd9d300a3b294070f839e5def87bbe94e137689a787d801eb0a1e2bc9
7
+ data.tar.gz: 4481ee2a4accca93a6fce56261e83aa4f3ca62787797d0b6ff2904ee5703d250bf333c7aa3c857eaa9e8537505b47022072be855f05092c588be5409e74918b7
@@ -122,10 +122,9 @@ module CoreFormHelper
122
122
  # Create the select tag
123
123
  #
124
124
  def form_select_tag(model, field, options = {})
125
- form_name = form_field_name(model, field, options)
126
125
  select_content = {
127
- id: form_name,
128
- name: form_name,
126
+ id: form_field_id(model, field, options),
127
+ name: form_field_name(model, field, options),
129
128
  class: options[:input_classes],
130
129
  disabled: options[:disabled]
131
130
  }
@@ -172,13 +171,12 @@ module CoreFormHelper
172
171
  # Checkbox field
173
172
  #
174
173
  def form_checkbox(model, field, classes = %w[s12 m6 l4 xl3], options = {})
175
- form_name = form_field_name model, field
176
174
  value = model.send(field)
177
175
  options[:disabled] ||= false
178
176
  properties = {
179
177
  class: 'validate',
180
- id: form_name,
181
- name: form_name,
178
+ id: form_field_id(model, field),
179
+ name: form_field_name(model, field),
182
180
  type: :checkbox,
183
181
  disabled: options[:disabled]
184
182
  }
@@ -245,7 +243,7 @@ module CoreFormHelper
245
243
  classes = value.nil? && place_holder.blank? ? '' : 'active'
246
244
  classes += error.present? ? ' invalid red-text' : ' valid'
247
245
  options[:class] = classes
248
- options[:for] = form_field_name(model, field, options)
246
+ options[:for] = form_field_id(model, field, options)
249
247
  options['data-error'] = error.join(', ') if error.present?
250
248
  content_tag(:label, options) do
251
249
  concat(I18n.exists?(key) ? I18n.t(key) : field.to_s.humanize)
@@ -260,7 +258,7 @@ module CoreFormHelper
260
258
  key = "ui_form.#{model.class.to_s.underscore}.hints.#{field}"
261
259
  return nil unless I18n.exists?(key)
262
260
 
263
- content_tag(:p, class: 'form-hint', for: form_field_name(model, field)) do
261
+ content_tag(:p, class: 'form-hint', for: form_field_id(model, field)) do
264
262
  concat(I18n.t(key))
265
263
  end
266
264
  end
@@ -269,7 +267,6 @@ module CoreFormHelper
269
267
  # Add the placeholder option if found in the translations
270
268
  #
271
269
  def text_field_options(model, field, options)
272
- form_name = form_field_name model, field, options
273
270
  hint_key = "ui_form.#{model.class.to_s.underscore}.hints.#{field}"
274
271
  if I18n.exists?(hint_key)
275
272
  classes = %w[validate tooltipped]
@@ -278,8 +275,8 @@ module CoreFormHelper
278
275
  classes = %w[validate]
279
276
  end
280
277
  classes += options[:input_classes] if options[:input_classes].present?
281
- options[:name] = form_name
282
- options[:id] = form_name
278
+ options[:name] = form_field_name(model, field, options)
279
+ options[:id] = form_field_id(model, field, options)
283
280
  place_holder = options[:place_holder] || field_place_holder(model, field)
284
281
  if place_holder.present?
285
282
  classes << 'active'
@@ -319,6 +316,30 @@ module CoreFormHelper
319
316
  end
320
317
  end
321
318
 
319
+ #
320
+ # Return a consistent form field id
321
+ #
322
+ def form_field_id(model, field, options = {})
323
+ return options[:form_id] if options[:form_id].present?
324
+
325
+ # TODO: Need to handle the other side of the 1:M use case where
326
+ # the field name needs to end in _ids, not _id.
327
+ field = "#{field}_id" if model.class.reflect_on_association(field).present?
328
+ if options[:index].present?
329
+ if options[:array_name].present?
330
+ if options[:base_name].present?
331
+ "#{options[:form_id_prefix]}#{options[:base_name]}[#{options[:array_name]}[#{options[:index]}][#{field}]]"
332
+ else
333
+ "#{options[:form_id_prefix]}#{options[:array_name]}[#{options[:index]}][#{field}]"
334
+ end
335
+ else
336
+ "#{options[:form_id_prefix]}#{model.class.to_s.underscore}[#{options[:index]}][#{field}]"
337
+ end
338
+ else
339
+ "#{options[:form_id_prefix]}#{model.class.to_s.underscore}[#{field}]"
340
+ end
341
+ end
342
+
322
343
  def form_radio_button(model, field, options = {})
323
344
  value = model.send(field)
324
345
  classes = (%w[input-field col] + options[:classes] || []).join(' ')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Web47core
4
- VERSION = '1.1.9'
4
+ VERSION = '1.1.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-25 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport