diff --git a/app/views/posts/_errors.haml b/app/views/posts/_errors.haml new file mode 100644 index 00000000..3b0a89dd --- /dev/null +++ b/app/views/posts/_errors.haml @@ -0,0 +1,19 @@ +- unless post.errors.empty? + - title = t('.errors.title') + - help = t('.errors.help') + = render 'bootstrap/alert' do + %h4= title + %p= help + + %ul + - post.errors.each do |attribute, errors| + - if errors.size > 1 + %li + %strong= post_label_t attribute, post: post + %ul + - errors.each do |error| + %li= error + - else + %li + %strong= post_label_t attribute, post: post + = errors.first diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 3e09cb72..1c9c623e 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -1,22 +1,4 @@ -- unless post.errors.empty? - - title = t('.errors.title') - - help = t('.errors.help') - = render 'bootstrap/alert' do - %h4= title - %p= help - - %ul - - post.errors.each do |attribute, errors| - - if errors.size > 1 - %li - %strong= post_label_t attribute, post: post - %ul - - errors.each do |error| - %li= error - - else - %li - %strong= post_label_t attribute, post: post - = errors.first += render 'errors', post: post -# TODO: habilitar form_for :ruby @@ -55,3 +37,11 @@ -# Formularios usados por los modales = yield(:post_form) + +-# + Acumulador de formularios dinĂ¡micos, se van cargando a medida que se + necesitan en lugar de recursivamente. + + Nunca se eliminan los modales una vez que se cargan para poder tener + historial de cambios. +%div{ data: { controller: 'htmx', action: 'htmx:getUrl@window->htmx#beforeend' } } diff --git a/app/views/posts/_htmx_form.haml b/app/views/posts/_htmx_form.haml index bd786cc6..75967a40 100644 --- a/app/views/posts/_htmx_form.haml +++ b/app/views/posts/_htmx_form.haml @@ -47,25 +47,7 @@ end = form_tag url, **options do - - unless post.errors.empty? - - title = t('.errors.title') - - help = t('.errors.help') - = render 'bootstrap/alert' do - %h4= title - %p= help - - %ul - - post.errors.each do |attribute, errors| - - if errors.size > 1 - %li - %strong= post_label_t attribute, post: post - %ul - - errors.each do |error| - %li= error - - else - %li - %strong= post_label_t attribute, post: post - = errors.first + = render 'errors', post: post -# ParĂ¡metros para HTMX %input{ type: 'hidden', name: 'hide', value: pluck_param((post.errors.empty? ? :show : :hide), optional: true) }