diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ff3ecb8e..28295793 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -128,7 +128,10 @@ class PostsController < ApplicationController render 'posts/new_has_many_value', layout: false else - # @todo Mostrar errores + headers['HX-Retarget'] = "##{params.require(:form)}" + headers['HX-Reswap'] = 'outerHTML' + + render 'posts/form', layout: false, post: post, site: site, **params.permit(:form, :base, :dir, :locale) end elsif @post.persisted? redirect_to site_post_path(@site, @post) diff --git a/app/views/posts/_htmx_form.haml b/app/views/posts/_htmx_form.haml index acb5585e..a288aa55 100644 --- a/app/views/posts/_htmx_form.haml +++ b/app/views/posts/_htmx_form.haml @@ -30,11 +30,38 @@ 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 + -# ParĂ¡metros para HTMX - %input{ type: 'hidden', name: 'hide', value: params.require(:show) } - %input{ type: 'hidden', name: 'show', value: params.require(:hide) } + %input{ type: 'hidden', name: 'hide', value: params.require((post.errors.empty? ? :show : :hide)) } + %input{ type: 'hidden', name: 'show', value: params.require((post.errors.empty? ? :hide : :show)) } %input{ type: 'hidden', name: 'name', value: params.require(:name) } %input{ type: 'hidden', name: 'base', value: params.require(:base) } + %input{ type: 'hidden', name: 'form', value: options[:id] } + %input{ type: 'hidden', name: 'dir', value: dir } + %input{ type: 'hidden', name: 'locale', value: locale } + %input{ type: 'hidden', name: 'target', value: params.require(:target) } + %input{ type: 'hidden', name: 'swap', value: params.require(:swap) } + - if params[:inverse].present? + %input{ type: 'hidden', name: 'inverse', value: params.require(:inverse) } = hidden_field_tag "#{base}[layout]", post.layout.name