diff --git a/app/javascript/controllers/modal_controller.js b/app/javascript/controllers/modal_controller.js index e6df3a19..bf2ce753 100644 --- a/app/javascript/controllers/modal_controller.js +++ b/app/javascript/controllers/modal_controller.js @@ -3,7 +3,8 @@ import { Controller } from "@hotwired/stimulus" // Connects to data-controller="modal" export default class extends Controller { connect() { - this.element.showModal(); + if (this.element.open) return + else this.element.showModal() } // Hide the dialog when the user clicks outside of it diff --git a/app/views/accounts/new.html.erb b/app/views/accounts/new.html.erb index 1cbac1ea..ac2ef743 100644 --- a/app/views/accounts/new.html.erb +++ b/app/views/accounts/new.html.erb @@ -1,11 +1,12 @@

<%= t('.title')%>

<%= modal do %> +
<% if @account.accountable.blank? %>
<%= t '.select_accountable_type' %>
-
+
@@ -38,7 +39,7 @@ <% end %> How would you like to add it?
-
+
@@ -67,16 +68,19 @@ Add <%= @account.accountable.model_name.human.downcase %>
- <%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "space-y-4 m-5 mt-1", data: { turbo: false } } do |f| %> - <%= f.hidden_field :accountable_type %> + <%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "m-5 mt-1 flex flex-col justify-between grow", data: { turbo: false } } do |f| %> +
+ <%= f.hidden_field :accountable_type %> - <%= f.text_field :name, placeholder: 'Example account name', required: 'required', label: 'Account name' %> + <%= f.text_field :name, placeholder: 'Example account name', required: 'required', label: 'Account name' %> - <%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %> + <%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %> - <%= f.number_field :balance, placeholder: number_to_currency(0), in: 0.00..100000000.00, required: 'required', label: true %> + <%= f.number_field :balance, placeholder: number_to_currency(0), in: 0.00..100000000.00, required: 'required', label: true %> +
<%= f.submit "Add #{@account.accountable.model_name.human.downcase}" %> <% end %> <% end %> +
<% end %>