5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 20:06:22 +00:00

feat: mostrar errores en los formularios

This commit is contained in:
f 2024-05-27 15:13:11 -03:00
parent f0769427b7
commit e2514a7f10
No known key found for this signature in database
2 changed files with 33 additions and 3 deletions

View file

@ -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)

View file

@ -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