xxxxxxxxxx
1
2
<!-- Start your project here-->
3
<div class="container">
4
<div class="d-flex justify-content-center align-items-center" style="height: 100vh;">
5
<div class="text-center">
6
<form class="row g-3 needs-validation" novalidate id="formtest">
7
<div class="col-md-4">
8
<div class="form-outline" data-mdb-input-init>
9
<input type="text" class="form-control" id="validationCustom01" value="Mark" required />
10
<label for="validationCustom01" class="form-label">First name</label>
11
<div class="valid-feedback">Looks good!</div>
12
</div>
13
</div>
14
<div class="col-md-4">
15
<div class="form-outline" data-mdb-input-init>
16
<input type="text" class="form-control" id="validationCustom02" value="Otto" required />
17
<label for="validationCustom02" class="form-label">Last name</label>
18
<div class="valid-feedback">Looks good!</div>
19
</div>
20
</div>
21
<div class="col-md-4">
22
<div class="input-group form-outline" data-mdb-input-init>
23
<span class="input-group-text" id="inputGroupPrepend">@</span>
24
<input type="text" class="form-control" id="validationCustomUsername" aria-describedby="inputGroupPrepend" required />
25
<label for="validationCustomUsername" class="form-label">Username</label>
26
<div class="invalid-feedback">Please choose a username.</div>
27
</div>
28
</div>
29
<div class="col-md-6">
30
<div class="form-outline" data-mdb-input-init>
31
<input type="text" class="form-control" id="validationCustom03" required />
32
<label for="validationCustom03" class="form-label">City</label>
33
<div class="invalid-feedback">Please provide a valid city.</div>
34
</div>
35
</div>
36
<div class="col-md-6">
37
<div class="form-outline" data-mdb-input-init>
38
<input type="text" class="form-control" id="validationCustom05" required />
39
<label for="validationCustom05" class="form-label">Zip</label>
40
<div class="invalid-feedback">Please provide a valid zip.</div>
41
</div>
42
</div>
43
<div class="col-12">
44
<div class="form-check">
45
<input class="form-check-input" type="checkbox" value="" id="invalidCheck" required />
46
<label class="form-check-label" for="invalidCheck">Agree to terms and conditions</label>
47
<div class="invalid-feedback">You must agree before submitting.</div>
48
</div>
49
</div>
50
<div class="col-12">
51
<button class="btn btn-primary" id="btnSubmit" type="button" data-mdb-ripple-init>Submit form</button>
52
</div>
53
</form>
54
55
</div>
56
</div>
57
</div>
58
<!-- End your project here-->
59
60
1
1
xxxxxxxxxx
1
2
document.getElementById('btnSubmit').addEventListener('click', function(event) {
3
var form = document.getElementById('formtest');
4
/*
5
I WANT TO ADD CUSTOM ACTIONS HERE
6
*/
7
if (!form.checkValidity()) {
8
event.preventDefault();
9
event.stopPropagation();
10
}
11
form.classList.add('was-validated');
12
var isFormValid = form.reportValidity();
13
if(isFormValid){
14
/*
15
PERFORM OTHER CUSTOM ACTIONS AND THEN SUBMIT THE FORM
16
*/
17
}
18
});
Console errors: 0