mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
[835] Auto-save in new Item Submission form breaks the form
Store additions: 1. Form AdditionalData: contains the list of the touched metadata 2. Submission metadata: contains the list of the metadata ids assignable for each section We keep also track whether a section ha focused fields or not.
This commit is contained in:
@@ -7,13 +7,13 @@ import { select, Store } from '@ngrx/store';
|
||||
import { AppState } from '../../app.reducer';
|
||||
import { formObjectFromIdSelector } from './selectors';
|
||||
import { FormBuilderService } from './builder/form-builder.service';
|
||||
import { 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,
|
||||
FormRemoveAction, FormRemoveErrorAction, FormSetAdditionalAction,
|
||||
FormStatusChangeAction
|
||||
} from './form.actions';
|
||||
import { FormEntry } from './form.reducer';
|
||||
@@ -51,6 +51,18 @@ export class FormService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve form's additional data from state
|
||||
*/
|
||||
public getFormAdditionalData(formId: string): Observable<any> {
|
||||
return this.store.pipe(
|
||||
select(formObjectFromIdSelector(formId)),
|
||||
filter((state) => isNotUndefined(state)),
|
||||
map((state) => state.additional),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to retrieve form's errors from state
|
||||
*/
|
||||
@@ -149,8 +161,8 @@ export class FormService {
|
||||
return (environment.form.validatorMap.hasOwnProperty(validator)) ? environment.form.validatorMap[validator] : validator;
|
||||
}
|
||||
|
||||
public initForm(formId: string, model: DynamicFormControlModel[], valid: boolean) {
|
||||
this.store.dispatch(new FormInitAction(formId, this.formBuilderService.getValueFromModel(model), valid));
|
||||
public initForm(formId: string, model: DynamicFormControlModel[], valid: boolean, additional?: any) {
|
||||
this.store.dispatch(new FormInitAction(formId, this.formBuilderService.getValueFromModel(model), valid, additional));
|
||||
}
|
||||
|
||||
public setStatusChanged(formId: string, valid: boolean) {
|
||||
@@ -169,6 +181,11 @@ export class FormService {
|
||||
this.store.dispatch(new FormChangeAction(formId, this.formBuilderService.getValueFromModel(model)));
|
||||
}
|
||||
|
||||
public setTouched(formId: string, model: DynamicFormControlModel[], event: DynamicFormControlEvent) {
|
||||
const ids = this.formBuilderService.getMetadataIdsFromEvent(event);
|
||||
this.store.dispatch(new FormSetAdditionalAction(formId, { touched: ids}));
|
||||
}
|
||||
|
||||
public removeError(formId: string, eventModelId: string, fieldIndex: number) {
|
||||
this.store.dispatch(new FormRemoveErrorAction(formId, eventModelId, fieldIndex));
|
||||
}
|
||||
|
Reference in New Issue
Block a user