11
11
<hr class =" w-50" />
12
12
<form id =" doctorReviewForm" asp-action =" Create" method =" post" >
13
13
<div asp-validation-summary =" ModelOnly" class =" text-danger" ></div >
14
- <div class =" form-check form-switch" >
15
- <input asp-for =" IsHealthy" class =" form-check-input" type =" checkbox" role =" switch" id =" flexSwitchCheckDefault" value =" true" >
16
- <label asp-for =" IsHealthy" class =" form-check-label" for =" flexSwitchCheckDefault" >@Html.DisplayNameFor(model => model.IsHealthy)</label >
17
- </div >
18
- <div class =" form-group w-50" >
14
+ <div class =" form-group w-50 mt-3" >
15
+ <label asp-for =" DriverId" >Haydovchi F.I.</label >
19
16
@if (ViewBag .SelectedDriverId != null && ViewBag .SelectedDriverId != 0 )
20
17
{
21
18
<select class =" form-control border border-dark" disabled >
37
34
}
38
35
}
39
36
</div >
40
-
37
+ <div class =" form-check form-switch mt-3" >
38
+ <input asp-for =" IsHealthy" class =" form-check-input is-invalid" type =" checkbox" role =" switch" id =" flexSwitchCheckDefault" value =" true" >
39
+ <label asp-for =" IsHealthy" class =" form-check-label" for =" flexSwitchCheckDefault" >Sog`ligi</label >
40
+ <div id =" checkboxError" class =" text-danger mt-2" ></div >
41
+ </div >
41
42
<div class =" form-group w-50" >
42
43
<select asp-for =" DoctorId" class =" form-control border border-dark d-none" asp-items =" @ViewBag.Doctors" ></select >
43
- <input type =" hidden" asp-for =" DoctorId" value =" @ViewBag.DoctorId" />
44
+ <input type =" hidden" asp-for =" DoctorId" value =" @ViewBag.DoctorId" />
44
45
</div >
45
- <div class =" form-group w-50" >
46
+ <div class =" form-group w-50 mt-3 " >
46
47
<label asp-for =" Comments" for =" exampleFormControlTextarea1" >Izoh</label >
47
48
<textarea asp-for =" Comments" class =" form-control" rows =" 4" ></textarea >
48
49
</div >
49
- <div class =" form-group mt-3 w-50" >
50
+ <div class =" form-group mt-3 w-50 mt-3 " >
50
51
<a asp-action =" PersonalIndex" class =" btn btn-outline-info" >
51
- <i class =" fa-solid fa-arrow-left-long" ></i > Back
52
+ <i class =" fa-solid fa-arrow-left-long" ></i > Orqaga
52
53
</a >
53
- <button class =" btn btn-outline- success" type =" submit" >
54
- <i class =" fa fa-plus" ></i > Create
54
+ <button class =" btn btn-success" type =" submit" >
55
+ <i class =" fa fa-plus" ></i > Yaratish
55
56
</button >
56
57
</div >
57
58
</form >
61
62
<script >
62
63
document .addEventListener (' DOMContentLoaded' , function () {
63
64
var form = document .getElementById (' doctorReviewForm' );
64
- form .addEventListener (' submit' , function () {
65
- var checkbox = document .getElementById (' flexSwitchCheckDefault' );
66
- var hiddenInput = document .createElement (' input' );
67
- hiddenInput .type = ' hidden' ;
68
- hiddenInput .name = ' IsHealthy' ;
69
- hiddenInput .value = checkbox .checked ? ' true' : ' false' ;
70
- form .appendChild (hiddenInput);
65
+ var checkbox = document .getElementById (' flexSwitchCheckDefault' );
66
+ var checkboxError = document .getElementById (' checkboxError' );
67
+
68
+ // Check initially if the checkbox is not checked
69
+ if (! checkbox .checked ) {
70
+ checkbox .classList .add (' is-invalid' );
71
+ checkboxError .classList .remove (' d-none' );
72
+ }
73
+
74
+ form .addEventListener (' submit' , function (event ) {
75
+ if (! checkbox .checked ) {
76
+ event .preventDefault (); // Prevent form submission
77
+ checkbox .classList .add (' is-invalid' ); // Add invalid class
78
+ checkboxError .classList .remove (' d-none' ); // Show error message
79
+ } else {
80
+ checkbox .classList .remove (' is-invalid' ); // Remove invalid class
81
+ checkboxError .classList .add (' d-none' ); // Hide error message
82
+ }
83
+ });
84
+
85
+ // Remove invalid class and error message when checkbox is checked
86
+ checkbox .addEventListener (' change' , function () {
87
+ if (checkbox .checked ) {
88
+ checkbox .classList .remove (' is-invalid' );
89
+ checkboxError .classList .add (' d-none' );
90
+ } else {
91
+ checkbox .classList .add (' is-invalid' );
92
+ checkboxError .classList .remove (' d-none' );
93
+ }
71
94
});
72
95
});
73
96
</script >
74
-
97
+
98
+ <style >
99
+ .is-invalid {
100
+ border-color : red !important ;
101
+ background-color : #f8d7da !important ;
102
+ }
103
+ </style >
0 commit comments