forked from fixin.me/fixin.me
Display errors for table-embedeed forms
This commit is contained in:
parent
2c0466b51a
commit
f298acd726
@ -1,6 +1,6 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
# TODO: replace legacy content_tag with tag.tagname
|
# TODO: replace legacy content_tag with tag.tagname
|
||||||
class TabularFormBuilder < ActionView::Helpers::FormBuilder
|
class LabelledFormBuilder < ActionView::Helpers::FormBuilder
|
||||||
(field_helpers - [:label]).each do |selector|
|
(field_helpers - [:label]).each do |selector|
|
||||||
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
||||||
def #{selector}(method, options = {})
|
def #{selector}(method, options = {})
|
||||||
@ -19,7 +19,7 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def table_form_for(&block)
|
def form_for(&block)
|
||||||
@template.content_tag(:table, class: "centered") { yield(self) } +
|
@template.content_tag(:table, class: "centered") { yield(self) } +
|
||||||
# Display leftover error messages (there shouldn't be any)
|
# Display leftover error messages (there shouldn't be any)
|
||||||
@template.content_tag(:div, @object&.errors.full_messages.join(@template.tag :br))
|
@template.content_tag(:div, @object&.errors.full_messages.join(@template.tag :br))
|
||||||
@ -50,9 +50,14 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tabular_form_for(record, options = {}, &block)
|
def labelled_form_for(record, options = {}, &block)
|
||||||
options.merge! builder: TabularFormBuilder
|
options.merge! builder: LabelledFormBuilder
|
||||||
form_for(record, **options, &-> (f) { f.table_form_for(&block) })
|
form_for(record, **options) { |f| f.form_for(&block) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def tabular_fields_for(record_name, record_object = nil, options = {}, &block)
|
||||||
|
flash.now[:alert] = record_name.errors.full_messages unless record_name.errors.empty?
|
||||||
|
fields_for(record_name, record_object, **options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def svg_tag(source, options = {})
|
def svg_tag(source, options = {})
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
<%= yield %>
|
||||||
|
|
||||||
|
<%# Some views may convert ActiveRecord errors to flashes, render at the end. %>
|
||||||
<%= turbo_stream.update :flashes do %>
|
<%= turbo_stream.update :flashes do %>
|
||||||
<%= render_flash_messages %>
|
<%= render_flash_messages %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= yield %>
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%= fields_for @unit do |form| %>
|
<%= tabular_fields_for @unit do |form| %>
|
||||||
<%= tag.tr id: dom_id(@unit), class: "form", onkeydown: "processKey(event)",
|
<%= tag.tr id: dom_id(@unit), class: "form", onkeydown: "processKey(event)",
|
||||||
data: {link_id: link_id} do %>
|
data: {link_id: link_id} do %>
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
<%= turbo_stream.close_form @unit %>
|
<%= turbo_stream.close_form @unit %>
|
||||||
|
<%= turbo_stream.update :flashes %>
|
||||||
<%#= turbo_stream.focus link_id %>
|
<%#= turbo_stream.focus link_id %>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<%= tabular_form_for resource, url: user_confirmation_path do |f| %>
|
<%= labelled_form_for resource, url: user_confirmation_path do |f| %>
|
||||||
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email",
|
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email",
|
||||||
value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
|
value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<%= tabular_form_for resource, url: user_password_path, html: {method: :put} do |f| %>
|
<%= labelled_form_for resource, url: user_password_path, html: {method: :put} do |f| %>
|
||||||
<%= f.hidden_field :reset_password_token, label: false %>
|
<%= f.hidden_field :reset_password_token, label: false %>
|
||||||
|
|
||||||
<%= f.password_field :password, label: t(".new_password"), required: true, size: 30,
|
<%= f.password_field :password, label: t(".new_password"), required: true, size: 30,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<%= tabular_form_for resource, url: user_password_path do |f| %>
|
<%= labelled_form_for resource, url: user_password_path do |f| %>
|
||||||
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
||||||
|
|
||||||
<%= f.submit t(:recover_password) %>
|
<%= f.submit t(:recover_password) %>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= tabular_form_for resource, url: registration_path(resource), html: {method: :patch} do |f| %>
|
<%= labelled_form_for resource, url: registration_path(resource), html: {method: :patch} do |f| %>
|
||||||
<%= f.email_field :email, size: 30, autofocus: true, autocomplete: "off" %>
|
<%= f.email_field :email, size: 30, autofocus: true, autocomplete: "off" %>
|
||||||
<% if f.object.pending_reconfirmation? %>
|
<% if f.object.pending_reconfirmation? %>
|
||||||
<%= f.text_field :unconfirmed_email, readonly: true, tabindex: -1,
|
<%= f.text_field :unconfirmed_email, readonly: true, tabindex: -1,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<%= tabular_form_for resource, url: user_registration_path do |f| %>
|
<%= labelled_form_for resource, url: user_registration_path do |f| %>
|
||||||
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
||||||
<%= f.password_field :password, required: true, size: 30,
|
<%= f.password_field :password, required: true, size: 30,
|
||||||
minlength: @minimum_password_length, autocomplete: "new-password",
|
minlength: @minimum_password_length, autocomplete: "new-password",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<%= tabular_form_for resource, url: user_session_path do |f| %>
|
<%= labelled_form_for resource, url: user_session_path do |f| %>
|
||||||
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, required: true, size: 30, autofocus: true, autocomplete: "email" %>
|
||||||
<%= f.password_field :password, required: true, size: 30, minlength: @minimum_password_length,
|
<%= f.password_field :password, required: true, size: 30, minlength: @minimum_password_length,
|
||||||
autocomplete: "current-password" %>
|
autocomplete: "current-password" %>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= tabular_form_for @user do |f| %>
|
<%= labelled_form_for @user do |f| %>
|
||||||
<%= f.email_field :email, readonly: true %>
|
<%= f.email_field :email, readonly: true %>
|
||||||
<% if f.object.pending_reconfirmation? %>
|
<% if f.object.pending_reconfirmation? %>
|
||||||
<%= f.email_field :unconfirmed_email, readonly: true,
|
<%= f.email_field :unconfirmed_email, readonly: true,
|
||||||
|
@ -13,6 +13,12 @@ en:
|
|||||||
created_at: registered
|
created_at: registered
|
||||||
confirmed_at: confirmed
|
confirmed_at: confirmed
|
||||||
unconfirmed_email: Awaiting confirmation for
|
unconfirmed_email: Awaiting confirmation for
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
unit:
|
||||||
|
attributes:
|
||||||
|
symbol:
|
||||||
|
taken: has to be unique
|
||||||
actioncontroller:
|
actioncontroller:
|
||||||
exceptions:
|
exceptions:
|
||||||
status:
|
status:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user