mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
[835] Auto-save in new Item Submission form breaks the form
Improved form touched state in ngrx store.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { map, distinctUntilChanged, filter } from 'rxjs/operators';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
|
||||
import { Observable } from 'rxjs';
|
||||
import { select, Store } from '@ngrx/store';
|
||||
@@ -7,16 +7,16 @@ import { select, Store } from '@ngrx/store';
|
||||
import { AppState } from '../../app.reducer';
|
||||
import { formObjectFromIdSelector } from './selectors';
|
||||
import { FormBuilderService } from './builder/form-builder.service';
|
||||
import {DynamicFormControlEvent, DynamicFormControlModel} from '@ng-dynamic-forms/core';
|
||||
import { DynamicFormControlEvent, DynamicFormControlModel } from '@ng-dynamic-forms/core';
|
||||
import { isEmpty, isNotUndefined } from '../empty.util';
|
||||
import { uniqueId } from 'lodash';
|
||||
import {
|
||||
FormChangeAction,
|
||||
FormInitAction,
|
||||
FormRemoveAction, FormRemoveErrorAction, FormSetAdditionalAction,
|
||||
FormRemoveAction, FormRemoveErrorAction, FormAddTouchedAction,
|
||||
FormStatusChangeAction
|
||||
} from './form.actions';
|
||||
import { FormEntry } from './form.reducer';
|
||||
import { FormEntry, FormTouchedState } from './form.reducer';
|
||||
import { environment } from '../../../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
@@ -52,13 +52,13 @@ export class FormService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve form's additional data from state
|
||||
* Method to retrieve form's touched state
|
||||
*/
|
||||
public getFormAdditionalData(formId: string): Observable<any> {
|
||||
public getFormTouchedState(formId: string): Observable<FormTouchedState> {
|
||||
return this.store.pipe(
|
||||
select(formObjectFromIdSelector(formId)),
|
||||
filter((state) => isNotUndefined(state)),
|
||||
map((state) => state.additional),
|
||||
map((state) => state.touched),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ export class FormService {
|
||||
|
||||
public setTouched(formId: string, model: DynamicFormControlModel[], event: DynamicFormControlEvent) {
|
||||
const ids = this.formBuilderService.getMetadataIdsFromEvent(event);
|
||||
this.store.dispatch(new FormSetAdditionalAction(formId, { touched: ids}));
|
||||
this.store.dispatch(new FormAddTouchedAction(formId, ids));
|
||||
}
|
||||
|
||||
public removeError(formId: string, eventModelId: string, fieldIndex: number) {
|
||||
|
Reference in New Issue
Block a user