Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DsDynamicSponsorAutocompleteComponent extends DsDynamicAutocomplete
if (suggestion instanceof ExternalSourceEntry) {
// suggestion from the openAIRE
fundingProjectCode = this.getProjectCodeFromId(suggestion?.id);
fundingName = suggestion.metadata?.['project.funder.name']?.[0]?.value;
fundingName = suggestion.metadata?.['dc.title']?.[0]?.value;
} else if (suggestion instanceof VocabularyEntry) {
// the value is in the format: `<FUNDING_TYPE>;<PROJECT_CODE>;<FUND_ORGANIZATION>;<FUNDING_NAME>;`
const fundingFields = suggestion.value?.split(SEPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { VocabularyService } from '../../../../../../core/submission/vocabularie
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model';
import { DsDynamicScrollableDropdownComponent } from '../scrollable-dropdown/dynamic-scrollable-dropdown.component';
import {
DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN,
DynamicScrollableDropdownModel
} from '../scrollable-dropdown/dynamic-scrollable-dropdown.model';
import {
Expand All @@ -19,6 +20,7 @@ import { DynamicComplexModel, EU_IDENTIFIER_INDEX } from '../ds-dynamic-complex.
import { DsDynamicInputModel } from '../ds-dynamic-input.model';
import { DYNAMIC_FORM_CONTROL_TYPE_AUTOCOMPLETE } from '../autocomplete/ds-dynamic-autocomplete.model';
import isEqual from 'lodash/isEqual';
import { TranslateService } from '@ngx-translate/core';

const DYNAMIC_INPUT_TYPE = 'INPUT';

Expand Down Expand Up @@ -47,7 +49,8 @@ export class DsDynamicSponsorScrollableDropdownComponent extends DsDynamicScroll
constructor(protected vocabularyService: VocabularyService,
protected cdr: ChangeDetectorRef,
protected layoutService: DynamicFormLayoutService,
protected validationService: DynamicFormValidationService
protected validationService: DynamicFormValidationService,
protected translateService: TranslateService
) {
super(vocabularyService, cdr, layoutService, validationService);
}
Expand Down Expand Up @@ -107,6 +110,9 @@ export class DsDynamicSponsorScrollableDropdownComponent extends DsDynamicScroll
case DYNAMIC_INPUT_TYPE:
(input as DsDynamicInputModel).value = '';
break;
case DYNAMIC_FORM_CONTROL_TYPE_SCROLLABLE_DROPDOWN:
(input as DynamicScrollableDropdownModel).value = '';
break;
default:
break;
}
Expand Down Expand Up @@ -135,6 +141,11 @@ export class DsDynamicSponsorScrollableDropdownComponent extends DsDynamicScroll
return true;
}

// if the funding type is `N/A` -> clean inputs
if (isEqual(fundingTypeValue, this.translateService.instant('autocomplete.suggestion.sponsor.empty'))) {
return true;
}

return false;
}
}
10 changes: 7 additions & 3 deletions src/app/shared/form/builder/parsers/complex-field-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ export class ComplexFieldParser extends FieldParser {
inputConfig.readOnly = true;
}

if (this.configData.mandatory) {
inputConfig.required = hasValue(complexDefinitionInput.required) && complexDefinitionInput.required === 'true';
}
inputConfig.required = hasValue(complexDefinitionInput.required) && complexDefinitionInput.required === 'true';

// max length - 200 chars
this.addValidatorToComplexInput(inputConfig, complexDefinitionInput);
Expand Down Expand Up @@ -155,6 +153,12 @@ export class ComplexFieldParser extends FieldParser {

// for non-EU funds hide EU identifier read only input field
inputModel.hidden = complexDefinitionInput.name === OPENAIRE_INPUT_NAME;

// Show error messages in the input field. It is ignored in the `initForm` because a whole input group is not
// required. It should be marked as required in the complex group for every input field.
if (inputConfig.required) {
this.markAsRequired(inputModel);
}
concatGroup.group.push(inputModel);
});

Expand Down
22 changes: 2 additions & 20 deletions src/app/shared/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { hasValue, isNotEmpty, isNotNull, isNull } from '../empty.util';
import { FormService } from './form.service';
import { FormEntry, FormError } from './form.reducer';
import { FormFieldMetadataValueObject } from './builder/models/form-field-metadata-value.model';
import {DsDynamicInputModel} from './builder/ds-dynamic-form-ui/models/ds-dynamic-input.model';

/**
* The default form component.
Expand Down Expand Up @@ -191,25 +190,8 @@ export class FormComponent implements OnDestroy, OnInit {
}

if (field) {
const model: DynamicFormControlModel = this.formBuilderService.findById(fieldId, formModel);

// Check if field has nested input fields
if (field instanceof UntypedFormGroup && isNotEmpty(field?.controls)) {
// For input field which consist of more input fields e.g. DynamicComplexModel
// add error for every input field
Object.keys(field.controls).forEach((nestedInputName, nestedInputIndex) => {
const nestedInputField = (model as DynamicFormGroupModel).group?.[nestedInputIndex];
const nestedInputFieldInForm = formGroup.get(this.formBuilderService.getPath(nestedInputField));
// Do not add errors for non-mandatory inputs
if (nestedInputField instanceof DsDynamicInputModel && !nestedInputField.required) {
return;
}
this.formService.addErrorToField(nestedInputFieldInForm, nestedInputField, error.message);
});
} else {
// Add error to the input field
this.formService.addErrorToField(field, model, error.message);
}
const model: DynamicFormControlModel = this.formBuilderService.findById(fieldId, formModel);
this.formService.addErrorToField(field, model, error.message);
this.changeDetectorRef.detectChanges();
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/form/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class FormService {
}

// if the field in question is a concat group, pass down the error to its fields
if (field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && this.formBuilderService.isConcatGroup(model)) {
if (field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && (this.formBuilderService.isConcatGroup(model) || this.formBuilderService.isComplexGroup(model))) {
model.group.forEach((subModel) => {
const subField = field.controls[subModel.id];

Expand All @@ -183,7 +183,7 @@ export class FormService {
}

// if the field in question is a concat group, clear the error from its fields
if (field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && this.formBuilderService.isConcatGroup(model)) {
if (field instanceof UntypedFormGroup && model instanceof DynamicFormGroupModel && (this.formBuilderService.isConcatGroup(model) || this.formBuilderService.isComplexGroup(model))) {
model.group.forEach((subModel) => {
const subField = field.controls[subModel.id];

Expand Down