Skip to content

Commit

Permalink
Add hidden field customization support
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Dec 16, 2024
1 parent 57ee6c9 commit 3eb6b00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/presenters/hotwire_combobox/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(
dialog_label: nil,
form: nil,
free_text: false,
hidden_field: {},
id: nil,
input: {},
label: nil,
Expand All @@ -30,9 +31,11 @@ def initialize(
request: nil,
value: nil, **rest)
@view, @autocomplete, @id, @name, @value, @form, @async_src, @label, @free_text, @request,
@preload, @name_when_new, @open, @data, @mobile_at, @multiselect_chip_src, @options, @dialog_label =
@preload, @name_when_new, @open, @data, @mobile_at, @multiselect_chip_src, @options, @dialog_label,
@hidden_field =
view, autocomplete, id, name.to_s, value, form, async_src, label, free_text, request,
preload, name_when_new, open, data, mobile_at, multiselect_chip_src, options, dialog_label
preload, name_when_new, open, data, mobile_at, multiselect_chip_src, options, dialog_label,
hidden_field

@combobox_attrs = input.reverse_merge(rest).deep_symbolize_keys
@association_name = association_name || infer_association_name
Expand All @@ -47,7 +50,8 @@ def render_in(view_context, &block)

private
attr_reader :view, :autocomplete, :id, :name, :value, :form, :free_text, :open, :request,
:data, :combobox_attrs, :mobile_at, :association_name, :multiselect_chip_src, :preload
:data, :combobox_attrs, :mobile_at, :association_name, :multiselect_chip_src, :preload,
:hidden_field

def canonical_id
@canonical_id ||= id || form&.field_id(name) || SecureRandom.uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module HotwireCombobox::Component::Markup::HiddenField
def hidden_field_attrs
customize :hidden_field, base: {
id: hidden_field_id, name: hidden_field_name, value: hidden_field_value,
data: { hw_combobox_target: "hiddenField" } }
data: { hw_combobox_target: "hiddenField" }
}.merge(hidden_field)
end

private
Expand Down

0 comments on commit 3eb6b00

Please sign in to comment.