Skip to content

Commit

Permalink
render the hidden input name properly
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopagno committed Jan 10, 2025
1 parent 17ccd5e commit 2f587af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
5 changes: 2 additions & 3 deletions app/forms/work_packages/types/subject_configuration_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ def has_pattern?(type)
subject_form.group(data: { "admin--subject-configuration-target": "patternInput" }) do |toggleable_group|
toggleable_group.pattern_autocompleter(
name: :subject_pattern,
pattern: subject_pattern,
value: subject_pattern,
suggestions: ::Types::Patterns::TokenPropertyMapper.new.tokens_for_type(model),
label: I18n.t("types.edit.subject_configuration.pattern.label"),
caption: I18n.t("types.edit.subject_configuration.pattern.caption"),
required: true,
input_width: :large
required: true
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ module OpenProject
module Forms
module Dsl
class PatternAutocompleterInput < Primer::Forms::Dsl::Input
attr_reader :name, :label, :pattern, :suggestions
attr_reader :name, :value, :suggestions

def initialize(name:, label:, pattern:, suggestions:, **system_arguments)
def initialize(name:, value:, suggestions:, **system_arguments)
@name = name
@label = label
@pattern = pattern
@value = value
@suggestions = suggestions

super(**system_arguments)
end

def to_component
PatternAutocompleter.new(name:, label:, pattern:, suggestions:)
PatternAutocompleter.new(input: self, value:, suggestions:)
end

def type
Expand Down
16 changes: 7 additions & 9 deletions lib/primer/open_project/forms/pattern_autocompleter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
:div,
class: "pattern-autocompleter",
"data-controller": "pattern-autocompleter",
"data-pattern-autocompleter-pattern-initial-value": @pattern
"data-pattern-autocompleter-pattern-initial-value": @value
) do
%>
<%=
render(
Primer::Alpha::TextField.new(
label: @label,
name: @name,
hidden: true, # set to false for debugging
value: @pattern,
data: { "pattern-autocompleter-target": "formInput" }
)
@input.builder.hidden_field(
name,
value: @value,
data: {
"pattern-autocompleter-target": "formInput"
}
)
%>

Expand Down
9 changes: 5 additions & 4 deletions lib/primer/open_project/forms/pattern_autocompleter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ module Primer
module OpenProject
module Forms
class PatternAutocompleter < Primer::Forms::BaseComponent
def initialize(name:, label:, pattern:, suggestions:)
delegate :name, to: :@input

def initialize(input:, value:, suggestions:)
super()
@name = name
@label = label
@pattern = pattern
@input = input
@value = value
@suggestions = suggestions
end

Expand Down

0 comments on commit 2f587af

Please sign in to comment.