mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 01:06:22 +00:00
feat: mostrar errores en los formularios
This commit is contained in:
parent
f0769427b7
commit
e2514a7f10
2 changed files with 33 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue