Client side puzzle image size validation
All checks were successful
CI / scan_ruby (push) Successful in 18s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 40s

This commit is contained in:
sto 2025-06-25 08:00:49 +02:00
parent 341e626f6f
commit c34b9654c8
3 changed files with 19 additions and 1 deletions

View File

@ -20,8 +20,24 @@
.form-text.mb-1 .form-text.mb-1
= t("puzzles.image_select") = t("puzzles.image_select")
= form.file_field :image, accept: "image/*", class: "form-control" = form.file_field :image, accept: "image/*", class: "form-control"
.form-text.error-message style="display: none;" id="image-error-message"
= t("puzzles.form.file_too_big")
javascript:
function setMaxUploadSize() {
const el = document.querySelector('input[type="file"]');
el.onchange = function() {
if(this.files[0].size > 2 * 1024 * 1024) {
document.getElementById('image-error-message').style.display = 'block';
this.value = "";
} else {
document.getElementById('image-error-message').style.display = 'none';
}
};
}
setMaxUploadSize();
.row.mt-4 .row.mt-4
.col .col
- if method == :patch - if method == :patch
= link_to "Delete", contest_puzzle_path(contest, puzzle), data: { turbo_method: :delete }, class: "btn btn-danger me-2" = link_to t("helpers.buttons.delete"), contest_puzzle_path(contest, puzzle), data: { turbo_method: :delete }, class: "btn btn-danger me-2"
= form.submit submit_text, class: "btn btn-primary" = form.submit submit_text, class: "btn btn-primary"

View File

@ -211,6 +211,7 @@ en:
title: Edit contest puzzle title: Edit contest puzzle
form: form:
fake_data_recommendation: It is recommended to first enter a fake name and image, and to use the real ones only once the contest starts. fake_data_recommendation: It is recommended to first enter a fake name and image, and to use the real ones only once the contest starts.
file_too_big: File too big! Maximum allowed size is 2M
image_select: Select an image image_select: Select an image
new: new:
notice: Puzzle added notice: Puzzle added

View File

@ -182,6 +182,7 @@ fr:
title: Modifier le puzzle title: Modifier le puzzle
form: form:
fake_data_recommendation: Il est recommendé d'entrer de faux noms et images, et de mettre les vrais uniquement quand le concours démarre. fake_data_recommendation: Il est recommendé d'entrer de faux noms et images, et de mettre les vrais uniquement quand le concours démarre.
file_too_big: La taille de l'image dépasse la taille maximum autorisée de 2M
image_select: Choisis une image image_select: Choisis une image
new: new:
notice: Puzzle ajouté notice: Puzzle ajouté