add length validation for event name and code fields

This commit is contained in:
Alex Lion
2025-05-30 17:20:11 +02:00
parent 4c1e4379c9
commit b4b5cfb756
4 changed files with 14 additions and 0 deletions

View File

@@ -9,6 +9,8 @@
- Fix settings panel on tablet-sized screens (#121)
- Fix question counting for quiz component
- Fix embed deletion bad keys for attendees
- Fix event name length validation (min: 5, max: 50)
- Fix event code length validation (min: 5, max: 10)
### v.2.3.1

View File

@@ -58,6 +58,8 @@ defmodule Claper.Events.Event do
|> cast_assoc(:presentation_file)
|> cast_assoc(:leaders)
|> validate_required([:code, :started_at])
|> validate_length(:code, min: 5, max: 10)
|> validate_length(:name, min: 5, max: 50)
|> downcase_code
|> put_change(:uuid, Ecto.UUID.generate())
end
@@ -76,6 +78,8 @@ defmodule Claper.Events.Event do
|> cast_assoc(:presentation_file)
|> cast_assoc(:leaders)
|> validate_required([:code, :started_at])
|> validate_length(:code, min: 5, max: 10)
|> validate_length(:name, min: 5, max: 50)
|> downcase_code
end

View File

@@ -271,6 +271,8 @@
name={gettext("Name of your event")}
autofocus="true"
required="true"
minlength="5"
maxlength="50"
/>
</div>

View File

@@ -14,6 +14,8 @@ defmodule ClaperWeb.Component.Input do
|> assign_new(:labelClass, fn -> "text-gray-700" end)
|> assign_new(:fieldClass, fn -> "bg-white" end)
|> assign_new(:value, fn -> input_value(assigns.form, assigns.key) end)
|> assign_new(:minlength, fn -> nil end)
|> assign_new(:maxlength, fn -> nil end)
~H"""
<div class="relative">
@@ -26,6 +28,8 @@ defmodule ClaperWeb.Component.Input do
placeholder: @placeholder,
autocomplete: @key,
value: @value,
minlength: @minlength,
maxlength: @maxlength,
class:
"#{@fieldClass} read-only:opacity-50 outline-none shadow-base focus:ring-primary-500 focus:border-primary-500 focus:ring-2 block w-full text-lg border-gray-300 rounded-md py-2 px-3"
) %>
@@ -210,6 +214,8 @@ defmodule ClaperWeb.Component.Input do
placeholder: @placeholder,
autofocus: @autofocus,
autocomplete: @key,
minlength: 5,
maxlength: 10,
class:
"read-only:opacity-50 outline-none shadow-base focus:ring-primary-500 focus:border-primary-500 block w-full text-lg border-gray-300 rounded-md py-2 pr-3 pl-9 uppercase"
) %>