Skip to content

Commit

Permalink
Add client-side validation for Album#released_on
Browse files Browse the repository at this point in the history
By adding a `max` attribute with today's date as the value, we can
prevent the album form from being submitted with an invalid (i.e.
future) date.

While this isn't very pretty (because it relies on native browser HTML
form validation), for most users it should prevent the scenario of
losing multiple uploaded tracks if an invalid release date is set.

Fixes #154.
floehopper committed Jan 18, 2024
1 parent bc2f50d commit 9ac051e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/albums/_form.html.erb
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" />
</svg>
</span> <p>File must be in <strong>jpeg</strong> or <strong>png</strong> format.</p></div>
<%= form.date_field :released_on, class: 'w-full mb-3' %>
<%= form.date_field :released_on, max: Time.zone.today, class: 'w-full mb-3' %>

<section id="tracks">
<h2 class="text-2xl tracking-tight leading-10 font-extrabold my-3">Tracks</h2>

0 comments on commit 9ac051e

Please sign in to comment.