Skip to content

Commit cffbc41

Browse files
committed
fix: #428 show required fields in form
1 parent 33eb123 commit cffbc41

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<span class="input-group-text span-width">Project</span>
99
</div>
1010
<select
11-
[class.is-invalid]="project_id.invalid && project_id.touched"
11+
[class.is-invalid]="project_id.invalid"
1212
required
1313
id="project_id"
1414
class="custom-select"
@@ -25,7 +25,7 @@
2525
<span class="input-group-text span-width">Activity</span>
2626
</div>
2727
<select
28-
[class.is-invalid]="activity_id.invalid && activity_id.touched"
28+
[class.is-invalid]="activity_id.invalid"
2929
required
3030
id="activity_id"
3131
class="custom-select"
@@ -122,7 +122,7 @@
122122
rows="3"></textarea>
123123
</div>
124124
<div class="modal-footer">
125-
<button type="submit" class="btn btn-primary" [disabled]="!entryForm.valid">Save</button>
125+
<button type="submit" class="btn btn-primary">Save</button>
126126
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
127127
Close
128128
</button>

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ describe('DetailsFieldsComponent', () => {
106106
expect(component).toBeTruthy();
107107
});
108108

109+
it('if form is invalid then no save is emited', () => {
110+
spyOn(component.saveEntry, 'emit');
111+
112+
component.onSubmit();
113+
114+
expect(component.saveEntry.emit).toHaveBeenCalledTimes(0);
115+
});
116+
109117
[
110118
{actionType: EntryActionTypes.CREATE_ENTRY_SUCCESS},
111119
{actionType: EntryActionTypes.UPDATE_ENTRY_SUCCESS},

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
22
import { filter } from 'rxjs/operators';
33
import { NumberFormatter } from './../../formatters/number.formatter';
44
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild, } from '@angular/core';
5-
import { FormBuilder, FormGroup } from '@angular/forms';
5+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
66
import { ActionsSubject, select, Store } from '@ngrx/store';
77
import { formatDate } from '@angular/common';
88

@@ -36,10 +36,11 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
3636
goingToWorkOnThis = false;
3737
shouldRestartEntry = false;
3838

39-
constructor(private formBuilder: FormBuilder, private store: Store<Merged>, private actionsSubject$: ActionsSubject) {
39+
constructor(private formBuilder: FormBuilder, private store: Store<Merged>,
40+
private actionsSubject$: ActionsSubject) {
4041
this.entryForm = this.formBuilder.group({
41-
project_id: '',
42-
activity_id: '',
42+
project_id: ['', Validators.required],
43+
activity_id: ['', Validators.required],
4344
description: '',
4445
entry_date: '',
4546
start_hour: '',
@@ -150,6 +151,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
150151
}
151152

152153
onSubmit() {
154+
if (this.entryForm.invalid) {
155+
return;
156+
}
153157
// start&end date same for now
154158
const entryDate = this.entryForm.value.entry_date;
155159
const entry = {

0 commit comments

Comments
 (0)