forked from fixin.me/fixin.me
@@ -65,7 +65,9 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
def tabular_fields_for(record_name, record_object = nil, options = {}, &block)
|
||||
options.merge! builder: TabularFormBuilder
|
||||
# skip_default_ids causes turbo to generate unique ID for element with [autofocus].
|
||||
# Otherwise IDs are not unique when multiple forms are open and the first input gets focus.
|
||||
options.merge! builder: TabularFormBuilder, skip_default_ids: true
|
||||
render_errors(record_name)
|
||||
fields_for(record_name, record_object, **options, &block)
|
||||
end
|
||||
|
||||
@@ -34,6 +34,13 @@ Turbo.StreamActions.hide = function() {
|
||||
|
||||
Turbo.StreamActions.close_form = function() {
|
||||
this.targetElements.forEach((e) => {
|
||||
/* Move focus if there's no focus or focus inside form being closed */
|
||||
const focused = document.activeElement
|
||||
if (!focused || (focused == document.body) || e.contains(focused)) {
|
||||
let nextForm = e.parentElement.querySelector(`#${e.id} ~ tr:has([autofocus])`)
|
||||
nextForm ??= e.parentElement.querySelector("tr:has([autofocus])")
|
||||
nextForm?.querySelector("[autofocus]").focus()
|
||||
}
|
||||
document.getElementById(e.getAttribute("data-form")).remove()
|
||||
if (e.hasAttribute("data-link")) {
|
||||
this.enableElement(document.getElementById(e.getAttribute("data-link")))
|
||||
|
||||
Reference in New Issue
Block a user