Skip to content

Commit 803e822

Browse files
committed
finished #2 questionnaire 2
1 parent dd52c93 commit 803e822

2 files changed

Lines changed: 49 additions & 39 deletions

File tree

src/pages/wizard/wizard.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h1 class="h1">Questionnaire 1/3</h1>
163163
</ion-item>
164164
<ion-item no-lines *ngIf="!disabilityValid && disabilityTouched" >
165165
<p class="invalid-text">Enter an option</p>
166-
</ion-item>
166+
</ion-item>
167167
</ion-item-group>
168168
</ion-card>
169169

@@ -178,7 +178,6 @@ <h1 class="h1">Questionnaire 1/3</h1>
178178
type="number"
179179
placeholder='Input Answer here..'
180180
formControlName="percentQuestionName"
181-
182181
>
183182
</ion-input>
184183
</ion-item>
@@ -205,7 +204,7 @@ <h1 class="h1">Questionnaire 2/3</h1>
205204

206205
<form [formGroup]="secondForm" (ngSubmit)="logFormTwo()" (ionChange)="formChanged()">
207206

208-
<ion-card>
207+
<ion-card [class.invalid]="employedInvalid && employedTouched">
209208
<ion-item-group>
210209
<ion-item-divider class='q-group' color="light">
211210
Are you employed or unemployed?
@@ -214,10 +213,13 @@ <h1 class="h1">Questionnaire 2/3</h1>
214213
<span class='question'>{{employedAnswer}}</span>
215214
<a class="select" (click)="showEmployedRadio()"> Select</a>
216215
</ion-item>
216+
<ion-item *ngIf="employedInvalid && employedTouched" >
217+
<p class="invalid-text">Enter an option</p>
218+
</ion-item>
217219
</ion-item-group>
218220
</ion-card>
219221

220-
<ion-card [class.invalid]="!secondForm.controls.lastEmployed.valid && (secondForm.controls.lastEmployed.touched)" *ngIf="showUnemployed">
222+
<ion-card [class.invalid]="!secondForm.controls.lastEmployed.valid && (secondForm.controls.lastEmployed.touched)" *ngIf="employedAnswer == 'Unemployed'">
221223
<ion-item-group>
222224
<ion-item-divider class='q-group' color="light">
223225
When were you last employed?
@@ -238,7 +240,7 @@ <h1 class="h1">Questionnaire 2/3</h1>
238240
</ion-item-group>
239241
</ion-card>
240242

241-
<ion-card>
243+
<ion-card [class.invalid]="!marriedValid && marriedTouched">
242244
<ion-item-group>
243245
<ion-item-divider class='q-group' color="light">
244246
Are you married?
@@ -247,6 +249,9 @@ <h1 class="h1">Questionnaire 2/3</h1>
247249
<span class='question'>{{marriedAnswer}}</span>
248250
<a class="select" (click)='showMarriedAlert()'>Select</a>
249251
</ion-item>
252+
<ion-item *ngIf="!marriedValid && marriedTouched" >
253+
<p class="invalid-text">Enter an option</p>
254+
</ion-item>
250255
</ion-item-group>
251256
</ion-card>
252257
<!-- <button ion-button type="submit" [disabled]="" (click)="onSubmit()" >submit</button> -->

src/pages/wizard/wizard.ts

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -337,29 +337,29 @@ export class WizardPage implements OnInit {
337337
disabilityTouched: boolean= false;
338338

339339
showRadioDisability() {
340-
let alert = this.alertCtrl.create(
340+
let disabilityAlert = this.alertCtrl.create(
341341
{
342342
title:"Dissability",
343343
cssClass: "branchRadio",
344344
message: "Select One"
345345
})
346346

347-
alert.addInput({
347+
disabilityAlert.addInput({
348348
type: 'radio',
349349
label: 'Yes',
350350
value: 'Yes',
351351
checked: false
352352
});
353353

354-
alert.addInput({
354+
disabilityAlert.addInput({
355355
type: 'radio',
356356
label: 'No',
357357
value: 'No',
358358
checked: false
359359
});
360360

361-
alert.addButton('Cancel');
362-
alert.addButton({
361+
disabilityAlert.addButton('Cancel');
362+
disabilityAlert.addButton({
363363
text: 'OK',
364364
handler: data => {
365365
const percentQuestion = this.firstForm.get('percentQuestionName')
@@ -376,16 +376,19 @@ export class WizardPage implements OnInit {
376376
}
377377
percentQuestion.updateValueAndValidity()
378378
this.disabilityQValue = data;
379-
this.disabilityTouched = true;
380-
}
379+
}
381380
});
382-
383-
alert.present();
381+
disabilityAlert.didLeave
382+
.subscribe( _ => {
383+
this.disabilityTouched = true;
384+
})
385+
disabilityAlert.present();
384386
}
385387

386388
//questionnaire ######2222222
387389
// show employed question
388-
showUnemployed: boolean = false;
390+
employedInvalid: boolean = true;
391+
employedTouched: boolean = false;
389392
employedAnswer: string= "";
390393
showEmployedRadio() {
391394
let alert = this.alertCtrl.create({
@@ -410,70 +413,72 @@ export class WizardPage implements OnInit {
410413
alert.addButton({
411414
text: 'OK',
412415
handler: data => {
413-
console.log("OK", data);
414-
this.employedAnswer = data;
415-
console.log(this.secondForm.valid, "2ndformValid?")
416-
console.log(this.secondForm, "2ndform")
417416
const lastEmployed = this.secondForm.get("lastEmployed")
418417
if(data == "Unemployed"){
419-
this.showUnemployed = true;
418+
this.employedInvalid = false;
420419
lastEmployed.setValidators(Validators.required)
421-
console.log("if -setValidators")
422420
} else if(data === "Employed") {
423-
this.showUnemployed = false;
421+
this.employedInvalid = false;
424422
lastEmployed.clearValidators()
425-
console.log("else -clearValidators", data)
426-
} else if (data === undefined) {
427-
this.showUnemployed = false;
423+
} else {
424+
this.employedInvalid = true;
428425
lastEmployed.clearValidators()
429-
console.log("else -clearValidators", data)
430426
}
427+
this.employedAnswer = data;
431428
lastEmployed.updateValueAndValidity()
432-
console.log("handler: updateValue")
433429
}
434430
});
431+
alert.didLeave
432+
.subscribe( _ => {
433+
this.employedTouched = true;
434+
})
435+
435436
alert.present();
436437
}
437438

438439
//question 2) Married
439440
marriedAnswer: string = '';
441+
marriedValid: boolean = false;
442+
marriedTouched: boolean = false;
440443
showMarriedAlert() {
441-
let alert = this.alertCtrl.create(
444+
let marriedAlert = this.alertCtrl.create(
442445
{
443446
title:"Married Status",
444447
cssClass: "branchRadio",
445448
message: "Select One"
446449
})
447450

448-
alert.addInput({
451+
marriedAlert.addInput({
449452
type: 'radio',
450453
label: 'Yes',
451454
value: 'Yes',
452455
checked: false
453456
});
454457

455-
alert.addInput({
458+
marriedAlert.addInput({
456459
type: 'radio',
457460
label: 'No',
458461
value: 'No',
459462
checked: false
460463
});
461464

462-
alert.addButton('Cancel');
463-
alert.addButton({
465+
marriedAlert.addButton('Cancel');
466+
marriedAlert.addButton({
464467
text: 'OK',
465468
handler: data => {
466-
console.log("OK", data);
467469
this.marriedAnswer = data;
468-
if(data == "Yes") {
469-
470-
} else if(data == "No"){
471-
470+
if(data) {
471+
this.marriedValid = true;
472+
}else {
473+
this.marriedValid = false;
472474
}
473475
}
474476
});
475-
476-
alert.present();
477+
marriedAlert.didLeave
478+
.subscribe( _ => {
479+
this.marriedTouched = true;
480+
})
481+
marriedAlert.present();
477482
}
478483

479484
logFormTwo(){

0 commit comments

Comments
 (0)