Skip to content

Commit

Permalink
Merge pull request opf#17136 from opf/fix/floating-form-and-error-msg
Browse files Browse the repository at this point in the history
Render errors for the `short` field of Hierarchy Items
  • Loading branch information
mereghost authored Nov 7, 2024
2 parents d8a75e7 + e3265c2 commit b022648
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def http_verb

def url
if model.new_record?
new_child_custom_field_item_path(root.custom_field_id, model.parent)
new_child_custom_field_item_path(root.custom_field_id, model.parent, position: model.sort_order)
else
custom_field_item_path(root.custom_field_id, model)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create
end,
lambda do |validation_result|
add_errors_to_form(validation_result)
render action: :new
render :new
end
)
end
Expand Down Expand Up @@ -129,7 +129,7 @@ def item_input
end

def add_errors_to_form(validation_result)
@new_item = ::CustomField::Hierarchy::Item.new(parent: @active_item, **validation_result.to_h)
@new_item = ::CustomField::Hierarchy::Item.new(**item_input)
validation_result.errors(full: true).to_h.each do |attribute, errors|
@new_item.errors.add(attribute, errors.join(", "))
end
Expand Down
3 changes: 2 additions & 1 deletion app/forms/custom_fields/hierarchy/item_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ItemForm < ApplicationForm
visually_hide_label: true,
full_width: false,
required: false,
placeholder: I18n.t("custom_fields.admin.items.placeholder.short")
placeholder: I18n.t("custom_fields.admin.items.placeholder.short"),
validation_message: validation_message_for(:short)
)
end

Expand Down

0 comments on commit b022648

Please sign in to comment.