feat: add weight validation in UI

This commit is contained in:
MohamedAliBouhaouala 2025-04-17 09:55:31 +01:00
parent f61e1ebba8
commit 8255f57abb
3 changed files with 29 additions and 7 deletions

View File

@ -121,7 +121,9 @@
"file_error": "File not found",
"audio_error": "Audio not found",
"video_error": "Video not found",
"missing_fields_error": "Please make sure that all required fields are filled"
"missing_fields_error": "Please make sure that all required fields are filled",
"weight_required_error": "Weight is required or invalid.",
"weight_positive_integer_error": "Weight must be a positive integer"
},
"menu": {
"terms": "Terms of Use",

View File

@ -121,7 +121,9 @@
"file_error": "Fichier introuvable",
"audio_error": "Audio introuvable",
"video_error": "Vidéo introuvable",
"missing_fields_error": "Veuillez vous assurer que tous les champs sont remplis correctement"
"missing_fields_error": "Veuillez vous assurer que tous les champs sont remplis correctement",
"weight_positive_integer_error": "Le poids doit être un nombre entier positif",
"weight_required_error": "Le poids est requis ou bien invalide"
},
"menu": {
"terms": "Conditions d'utilisation",

View File

@ -135,11 +135,29 @@ export const NlpEntityVarForm: FC<ComponentFormProps<INlpEntity>> = ({
/>
</ContentItem>
<ContentItem>
<Input
label={t("label.weight")}
{...register("weight", { valueAsNumber: true })}
type="number"
inputProps={{ min: 1, step: 1 }} // Restricts input to positive integers only
<Input
label={t("label.weight")}
{...register("weight", {
valueAsNumber: true,
required: t("message.weight_required_error"),
min: {
value: 1,
message: t("message.weight_positive_integer_error"),
},
validate: (value) =>
Number.isInteger(value) && value > 0
? true
: t("message.weight_positive_integer_error"),
})}
type="number"
inputProps={{
min: 1,
step: 1,
inputMode: "numeric",
pattern: "[1-9][0-9]*",
}}
error={!!errors.weight}
helperText={errors.weight?.message}
/>
</ContentItem>
</ContentContainer>