Skip to content

Commit 4ea708c

Browse files
authored
Merge pull request #371 from navikt/TOLK-2788
TOLK-2788 - Legge til påkrevd felter når de vises
2 parents c2b32c0 + 2ae0d69 commit 4ea708c

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

force-app/main/default/lwc/courseRegistrationForm/courseRegistrationForm.js

+45-11
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,53 @@ export default class CourseRegistrationForm extends NavigationMixin(LightningEle
124124

125125
handleSubmit(event) {
126126
event.preventDefault();
127-
if (this.theRecord.firstName && this.theRecord.lastName && this.theRecord.email && this.theRecord.phone) {
128-
let output = JSON.stringify(this.theRecord, null);
129-
createRegistration({
130-
fields: output,
131-
courseId: this.courseId
132-
}).then((result) => {
133-
this.showForm = false;
134-
this.showConfirmation = true;
135-
this.message = result;
136-
});
137-
} else {
127+
128+
// Basis felter som alltid vises
129+
if (!this.theRecord.firstName || !this.theRecord.lastName || !this.theRecord.email || !this.theRecord.phone) {
130+
this.showError = true;
131+
return;
132+
}
133+
134+
// Tillegs felter sjekk om de er satt
135+
if (this.companyName && !this.theRecord.companyName) {
136+
this.showError = true;
137+
return;
138+
}
139+
if (this.county && !this.theRecord.county) {
140+
this.showError = true;
141+
return;
142+
}
143+
if (this.role && !this.theRecord.role) {
138144
this.showError = true;
145+
return;
139146
}
147+
if (this.allergies && !this.theRecord.allergies) {
148+
this.showError = true;
149+
return;
150+
}
151+
if (this.invoiceAdress && !this.theRecord.invoiceAdress) {
152+
this.showError = true;
153+
return;
154+
}
155+
if (this.invoiceReference && !this.theRecord.invoiceReference) {
156+
this.showError = true;
157+
return;
158+
}
159+
if (this.workplace && !this.theRecord.workplace) {
160+
this.showError = true;
161+
return;
162+
}
163+
164+
// Alle sjekker er passert om vi kommer hit
165+
let output = JSON.stringify(this.theRecord, null);
166+
createRegistration({
167+
fields: output,
168+
courseId: this.courseId
169+
}).then((result) => {
170+
this.showForm = false;
171+
this.showConfirmation = true;
172+
this.message = result;
173+
});
140174
}
141175

142176
validateCode(event) {

0 commit comments

Comments
 (0)