//formulaire véhicule <div class="container mx-auto"> <div class="flex justify-between…
- User
//formulaire véhicule
code - Assistant
- User
je veux que tu arranges mes formulaires en me donnant le code entier avec les memes formcontrolname
- Assistant
//formulaire véhicule
je veux que tu arranges mes formulaires en me donnant le code entier avec les memes formcontrolname
<div class="sm:col-span-1">
<div class="mb-2 block">
<label class="font-medium mb-1">Constructeur</label>
<select
(change)="getModele($event)"
id="constructeur" name="constructeur" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="Libelle">
<option *ngFor="let constructeur of constructeurs " [value]="constructeur.Id">{{ constructeur.Libelle }}</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Libelle')?.hasError('required') && (vehicleForm.get('Libelle')?.dirty || vehicleForm.get('Libelle')?.touched)">
Ce champs est requis
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="model" class="font-medium mb-1">Modèle</label>
<select
id="model" name="model" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="Libelle">
<option *ngFor="let modele of modeles" [value]="modele.Id">{{ modele.Libelle }}</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Libelle')?.hasError('required') && (vehicleForm.get('Libelle')?.dirty || vehicleForm.get('Libelle')?.touched)">
Ce champs est requis
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="date_mise_en_circulation" class="font-medium mb-1">Date de mise en circulation</label>
<input type="date" id="date_mise_en_circulation" name="date_mise_en_circulation" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="DateMiseEnCirculation">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('DateMiseEnCirculation')?.hasError('required') && (vehicleForm.get('DateMiseEnCirculation')?.dirty || vehicleForm.get('DateMiseEnCirculation')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Number Plate -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="numberplate" class="font-medium mb-1">Numéro de série</label>
<input type="text" id="numberplate" name="numberplate" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Numéro de série" formControlName="NumeroSerie">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('NumeroSerie')?.hasError('invalidSerialNumber') && (vehicleForm.get('NumeroSerie')?.dirty || vehicleForm.get('NumeroSerie')?.touched)">
Le format du numéro de série n’est pas valide.
</small>
</div>
</div>
<!-- Registration Date -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="registration_date" class="font-medium mb-1">Immatriculation</label>
<input type="text" id="registration_date" name="registration_date" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 fo
cus:border-blue-500 block w-full p-2.5" placeholder="Immatriculation" formControlName="Immatriculation"> <small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Immatriculation')?.hasError('invalidRegistrationNumber') && (vehicleForm.get('Immatriculation')?.dirty || vehicleForm.get('Immatriculation')?.touched)"> Le format de l’immatriculation n’est pas valide.
<!-- Kilometerage -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="kilometrage" class="font-medium mb-1">Kilométrage</label>
<input type="number" id="kilometrage" name="kilometrage" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Kilométrage" formControlName="Kilometrage">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Kilometrage')?.hasError('required') && (vehicleForm.get('Kilometrage')?.dirty || vehicleForm.get('Kilometrage')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="critair" class="font-medium mb-1">Critair</label>
<select id="critair" name="critair" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="VignetteCritair">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('VignetteCritair')?.hasError('required') && (vehicleForm.get('VignetteCritair')?.dirty || vehicleForm.get('VignetteCritair')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Validity of Critair Stickers-->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="validitycritair" class="font-medium mb-1">Validité Crit'Air</label>
<input type="date" id="validitycritair" name="validitycritair" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="ValiditeCritair">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('ValiditeCritair')?.hasError('required') && (vehicleForm.get('ValiditeCritair')?.dirty || vehicleForm.get('ValiditeCritair')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Acquisition Date -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="DateAchat" class="font-medium mb-1">Date d'acquisition</label>
<input type="date" id="DateAchat" name="DateAchat" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="DateAchat">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('DateAchat')?.hasError('required') && (vehicleForm.get('DateAchat')?.dirty || vehicleForm.get('DateAchat')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Vehicle Type -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="vehicle_type" class="font-medium mb-1">Type de véhicule</label>
<select id="vehicle_type" name="vehicle_type" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="TypeVehicule">
<option value="Voiture">Voiture</option>
<option value="Moto">Moto</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('TypeVehicule')?.hasError('required') && (vehicleForm.get('TypeVehicule')?.dirty || vehicleForm.get('TypeVehicule')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="numeroassurance" class="font-medium mb-1">Numéro d'assurance</label>
<input type="text" id="numeroassurance" name="numeroassurance" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Numéro d'assurance" formControlName="NumeroAssurance">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('NumeroAssurance')?.hasError('required') && (vehicleForm.get('NumeroAssurance')?.dirty || vehicleForm.get('NumeroAssurance')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="consommation" class="font-medium mb-1">Consommation moyenne</label>
<input type="number" id="consommation" name="consommation" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Consommation moyenne" formControlName="ConsommationMoyenne">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('ConsommationMoyenne')?.hasError('required') && (vehicleForm.get('ConsommationMoyenne')?.dirty || vehicleForm.get('ConsommationMoyenne')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="prixAchat" class="font-medium mb-1">Prix d'achat</label>
<input type="number" id="prixAchat" name="prixAchat" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Prix d'achat" formControlName="PrixAchat">
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('PrixAchat')?.hasError('required') && (vehicleForm.get('PrixAchat')?.dirty || vehicleForm.get('PrixAchat')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Driver -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="driver" class="font-medium mb-1">Chauffeur associé</label>
<select id="driver" name="driver" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="IdConducteur">
<option *ngFor="let driver of drivers" [value]="driver.Id">{{ driver.Nom }}</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('IdConducteur')?.hasError('required') && (vehicleForm.get('IdConducteur')?.dirty || vehicleForm.get('IdConducteur')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<!-- Acquisition Status -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="Achat" class="font-medium mb-1">Achat</label>
<select id="Achat" name="Achat" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-border-blue-500 block w-full p-2.5" formControlName="Achat">
<option value="Oui">Oui</option>
<option value="Non">Non</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Achat')?.hasError('required') && (vehicleForm.get('Achat')?.dirty || vehicleForm.get('Achat')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="location" class="font-medium mb-1">Location</label>
<select id="location" name="location" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" formControlName="Location">
<option value="Oui">Oui</option>
<option value="Non">Non</option>
</select>
<small class="text-red-600 mt-1" *ngIf="vehicleForm.get('Location')?.hasError('required') && (vehicleForm.get('Location')?.dirty || vehicleForm.get('Location')?.touched)">
Ce champs est requis.
</small>
</div>
</div>
<div class="max-w-2xl mx-auto">
<aside class="flex flex-col items-center justify-center mb-5" aria-label="Sidebar">
<div class="px-3 py-4 overflow-y-auto rounded-2xl bg-gray-50 dark:bg-gray-800">
<ul class="space-y-2">
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-200">Modèle caractéristique du véhicule</h2>
<!-- Category -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1">Segment : </label>
{{modelecarac.Segment }}
</div>
</div>
<!-- Capacity -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1">Nombre de places :</label>
{{modelecarac.NombrePlaces }}
</div>
</div>
<!-- Engine Size -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1">Cylindrée :</label>
{{modelecarac.Cylindree}}
</div>
</div>
<!-- Weight -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1" >Poids :</label>
{{modelecarac.Poids}}
</div>
</div>
<!-- Carbon Emissions -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1">Emission de CO2 :</label>
{{modelecarac.EmissionCO2}}
</div>
</div>
<!-- Fuel Type -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1" formControlName="TypeCarburant">Type de carburant :</label>
{{modelecarac.TypeCarburant}}
</div>
</div>
<!-- Transmission Type -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1" formControlName="TypeBoiteVitesse">Type de transmission :</label>
{{modelecarac.TypeBoiteVitesse}}
</div>
</div>
<!-- Power to weight Ratio -->
<div class="sm:col-span-1">
<div class="mb-2 block" *ngFor="let modelecarac of modelecaracteristique ">
<label class="font-medium mb-1">Rapport Poids Puissance :</label>
{{modelecarac.RapportPoidsPuissance}}
</div>
</div>
</ul>
</div>
</aside>
Your code snippets consist of several Angular forms for a vehicle management system, including vehicle registration, option selection, and vehicle model specification. Here's a brief overview and suggestions for improvement:
This form collects detailed information about a vehicle, such as the manufacturer, model, date of first registration, serial number, mileage, Crit'Air sticker (French air quality certificate), consumption, price, and associated driver among others. Noticeable features:
constructeur, model, and driver.Suggestions for Improvement:
formControlName attributes correctly match the property names expected in your TypeScript code. For example, formControlName="Libelle" is used for both "Constructeur" and "Modèle," which might lead to conflicts. Each field should have a unique form control name that maps to a distinct property in your form group.This secondary form allows associating options with a vehicle. It features:
Suggestions for Improvement:
formControlName correctly maps to your form model and that each control name is unique to avoid any data binding issues.This form seems to handle the specifications of a vehicle model, like the label, segment, and number of seats.
Suggestions for Improvement:
aria-labels and ensuring that interactive elements are keyboard-navigable.Your forms provide a solid foundation for a vehicle management system's UI. With focused refinements, especially around data validation and form control organization, the usability and robustness of the forms can be significantly enhanced.
Pour simplifier et organiser vos formulaires avec le respect de leurs formControlName uniques tout en gardant la structure que vous avez fournie, je vais procéder à quelques modifications tout en gardant les mêmes noms de formControlName quand c'est approprié. Pour éviter les confusions et les erreurs, chaque select et input aura un formControlName unique selon son usage.
Je vais également corriger les formControlName pour le formulaire modèle du véhicule à la fin, car ils semblent ne pas correspondre parfaitement avec votre description.
<div class="container mx-auto">
<div class="flex justify-between items-center">
<form [formGroup]="vehicleForm" (ngSubmit)="onSubmitVehicule()">
<div class="space-y-4 w-full md:w-2/3 mx-auto">
<!-- Constructeur -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label class="font-medium mb-1">Constructeur</label>
<select (change)="getModele($event)" id="constructeur" name="constructeur" class="bg-gray-50 border..." formControlName="constructeurId">
<option *ngFor="let constructeur of constructeurs" [value]="constructeur.Id">{{ constructeur.Libelle }}</option>
</select>
<!-- Validation et autres champs similaires omis pour la brièveté -->
</div>
</div>
<!-- Modèle -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="model" class="font-medium mb-1">Modèle</label>
<select id="model" name="model" class="bg-gray-50 border..." formControlName="modeleId">
<option *ngFor="let modele of modeles" [value]="modele.Id">{{ modele.Libelle }}</option>
</select>
</div>
</div>
<!-- Date de mise en circulation -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="date_mise_en_circulation" class="font-medium mb-1">Date de mise en circulation</label>
<input type="date" id="date_mise_en_circulation" name="date_mise_en_circulation" class="bg-gray-50 border..." formControlName="dateMiseEnCirculation">
</div>
</div>
<!-- Numéro de série -->
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="numberplate" class="font-medium mb-1">Numéro de série</label>
<input type="text" id="numberplate" name="numberplate" class="bg-gray-50 border..." placeholder="Numéro de série" formControlName="numeroSerie">
</div>
</div>
<!-- D'autres champs omis pour la brièveté -->
<div class="flex justify-around my-8">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Enregistrer</button>
</div>
</div>
</form>
</div>
</div>
<form class="space-y-4 w-full md:w-2/3 mx-auto" [formGroup]="optionService.optionForm" (ngSubmit)="onSubmitOption()">
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="option" class="font-medium mb-1">Option</label>
<select id="option" name="option" class="bg-gray-50 border..." formControlName="optionId">
<option *ngFor="let option of options" [value]="option.id">{{ option.name }}</option>
</select>
</div>
<!-- Select element for choosing a vehicle -->
<div class="mt-4">
<label for="vehicules" class="block font-medium mb-1">Choisir un véhicule</label>
<select id="vehicules" name="vehicules" class="bg-gray-50 border..." formControlName="vehiculeId">
<option *ngFor="let vehicule of vehicules" [value]="vehicule.Id">{{ vehicule.contructeur }} {{ vehicule.modele }} {{ vehicule.immatriculation }}</option>
</select>
</div>
<div class="flex justify-around my-8">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Enregistrer</button>
<button type="reset" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">Annuler</button>
</div>
</div>
</form>
Je suppose que chacun des champs dans ce formulaire doit être unique, donc voici une version ajustée:
<form [formGroup]="modeleForm" (ngSubmit)="onSubmitModele()">
<div class="sm:col-span-1">
<div class="mb-2 block">
<label for="libelleModel" class="font-medium mb-1">Libelle</label>
<input type="text" id="libelleModel" name="libelleModel" class="bg-gray-50 border..." placeholder="Libelle" formControlName="libelle">
</div>
<!-- D'autres champs similaires pour segment, nombre de places, etc. -->
</div>
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Enregistrer</button>
</form>
Remarques Importantes : J'ai utilisé des ellipses (...) pour indiquer où le code CSS ou d'autres attributs ont été omis pour simplifier. Remplacez ces parties avec vos propres valeurs selon besoin. Les noms exacts des formControlName doivent correspondre à ceux définis dans vos classes TypeScript pour le fonctionnement correct des formulaires.