diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fcbd4074..c83b2894 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,6 +2,8 @@ # Helpers module ApplicationHelper + BRACKETS = /[\[\]]/ + # Devuelve el atributo name de un campo anidado en el formato que # esperan los helpers *_field # @@ -19,6 +21,14 @@ module ApplicationHelper [root, name] end + # Obtiene un ID + # + # @param base [String] + # @param attribute [String, Symbol] + def id_for(base, attribute) + "#{base.gsub(BRACKETS, '_')}_#{attribute}".squeeze('_') + end + def plain_field_name_for(*names) root, name = field_name_for(*names) diff --git a/app/views/posts/_htmx_form.haml b/app/views/posts/_htmx_form.haml index 25c45aad..cd482b35 100644 --- a/app/views/posts/_htmx_form.haml +++ b/app/views/posts/_htmx_form.haml @@ -7,6 +7,7 @@ @param :dir [Symbol, String] :ruby options = { + id: base, multipart: true, class: 'form post ', 'hx-swap': params.require(:swap), @@ -29,13 +30,7 @@ %input{ type: 'hidden', name: 'name', value: params.require(:name) } %input{ type: 'hidden', name: 'base', value: params.require(:base) } - -# Botones de guardado - = render 'posts/submit', site: site, post: post - = hidden_field_tag "#{base}[layout]", post.layout.name -# Dibuja cada atributo = render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale - - -# Botones de guardado - = render 'posts/submit', site: site, post: post diff --git a/app/views/posts/attributes/_new_array.haml b/app/views/posts/attributes/_new_array.haml index 08fc6dee..b4407c0d 100644 --- a/app/views/posts/attributes/_new_array.haml +++ b/app/views/posts/attributes/_new_array.haml @@ -1,7 +1,7 @@ -# Genera un listado de checkboxes entre los que se puede elegir para guardar :ruby - id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_') + id = id_for(base, attribute) name = "#{base}[#{attribute}][]" form_id = "form-#{Nanoid.generate}" diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index 48230759..275d0335 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -8,7 +8,7 @@ del formulario principal porque no se pueden anidar. :ruby - id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_') + id = id_for(base, attribute) name = "#{base}[#{attribute}][]" form_id = "form-#{Nanoid.generate}" modal_id = "modal-#{Nanoid.generate}" @@ -90,3 +90,5 @@ = render 'bootstrap/modal', id: post_id, modal_content_attributes: { class: 'h-100' } do - content_for :"#{post_id}_body" do %div{ id: post_form_loaded_id } + - content_for :"#{post_id}_footer" do + = render 'bootstrap/btn', form: id, content: t('.save'), type: 'submit' diff --git a/app/views/posts/attributes/_new_predefined_array.haml b/app/views/posts/attributes/_new_predefined_array.haml index 218a2cc2..36f1ae2f 100644 --- a/app/views/posts/attributes/_new_predefined_array.haml +++ b/app/views/posts/attributes/_new_predefined_array.haml @@ -3,8 +3,7 @@ guardar, pero no se pueden agregar nuevos. :ruby - # @todo Convertir en un helper - id = "#{base.gsub(/[\[\]]/, '_')}_#{attribute}".squeeze('_') + id = id_for(base, attribute) name = "#{base}[#{attribute}][]" form_id = "form-#{Nanoid.generate}" diff --git a/config/locales/en.yml b/config/locales/en.yml index 821a6735..a68b32c0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -946,3 +946,4 @@ en: cancel: "Cancel" edit: "Edit" filter: "Start typing to filter..." + save: "Save" diff --git a/config/locales/es.yml b/config/locales/es.yml index 3d70292e..eb58b461 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -954,3 +954,4 @@ es: cancel: "Cancelar" edit: "Editar" filter: "Empezá a escribir para filtrar..." + save: "Guardar"