|
1 | 1 | <template>
|
2 |
| - <div class="pkpFormField pkpFormField--affiliations"> |
| 2 | + <!-- To be able to scroll to this field on error--> |
| 3 | + <div |
| 4 | + :id="`${props.formId}-${props.name}`" |
| 5 | + class="pkpFormField pkpFormField--affiliations" |
| 6 | + > |
3 | 7 | <div class="pkpFormField__heading">
|
4 | 8 | <label class="pkpFormFieldLabel">
|
5 | 9 | {{ t('user.affiliations', {}) }}
|
|
70 | 74 | />
|
71 | 75 | {{ translations(affiliation).label }}
|
72 | 76 | </a>
|
73 |
| - <div v-if="affiliationIndex === indexEditMode"> |
| 77 | + <div |
| 78 | + v-if=" |
| 79 | + affiliationIndex === indexEditMode || |
| 80 | + errors?.[affiliationIndex]?.name |
| 81 | + " |
| 82 | + > |
74 | 83 | <div
|
75 | 84 | v-for="[affiliationNameLocale] in Object.entries(
|
76 | 85 | affiliation.name,
|
|
80 | 89 | <div
|
81 | 90 | v-if="supportedLocales.includes(affiliationNameLocale)"
|
82 | 91 | >
|
83 |
| - <div> |
84 |
| - <span class="text-lg-semibold"> |
85 |
| - {{ getTextFieldLabel(affiliationNameLocale) }} |
86 |
| - </span> |
87 |
| - <span |
88 |
| - v-if="affiliationNameLocale === primaryLocale" |
89 |
| - class="pkpFormFieldLabel__required" |
90 |
| - > |
91 |
| - <span class="aria-hidden">*</span> |
92 |
| - <span class="-screenReader">Required</span> |
93 |
| - </span> |
94 |
| - </div> |
95 |
| - <div class="pkpFormField--sizelarge"> |
96 |
| - <input |
97 |
| - :id=" |
98 |
| - 'contributors-affiliations-' + |
99 |
| - affiliationIndex + |
100 |
| - '-' + |
| 92 | + <FieldText |
| 93 | + :label="getTextFieldLabel(affiliationNameLocale)" |
| 94 | + :value="affiliation.name[affiliationNameLocale]" |
| 95 | + name="name" |
| 96 | + :all-errors="{ |
| 97 | + name: errors?.[affiliationIndex]?.name?.[ |
101 | 98 | affiliationNameLocale
|
102 |
| - " |
103 |
| - v-model="affiliation.name[affiliationNameLocale]" |
104 |
| - :name=" |
105 |
| - 'contributors-affiliations-' + |
106 |
| - affiliationIndex + |
107 |
| - '-' + |
108 |
| - affiliationNameLocale |
109 |
| - " |
110 |
| - class="pkpFormField__input pkpFormField--text__input" |
111 |
| - type="text" |
112 |
| - :aria-invalid="false" |
113 |
| - /> |
114 |
| - <FieldError |
115 |
| - v-if=" |
116 |
| - affiliationNameLocale === primaryLocale && |
117 |
| - !affiliation.name[affiliationNameLocale].trim() |
118 |
| - " |
119 |
| - :messages="[t('validator.required', {})]" |
120 |
| - /> |
121 |
| - </div> |
| 99 | + ], |
| 100 | + }" |
| 101 | + size="large" |
| 102 | + :is-required="affiliationNameLocale === primaryLocale" |
| 103 | + @change=" |
| 104 | + (fieldName, _, fieldValue) => { |
| 105 | + updateAffiliationName( |
| 106 | + affiliationIndex, |
| 107 | + affiliationNameLocale, |
| 108 | + fieldValue, |
| 109 | + ); |
| 110 | + } |
| 111 | + " |
| 112 | + /> |
122 | 113 | </div>
|
123 | 114 | </div>
|
124 | 115 | </div>
|
|
128 | 119 | <DropdownActions
|
129 | 120 | v-if="!(affiliationIndex === indexEditMode)"
|
130 | 121 | v-bind="rowActionsArgs(affiliationIndex)"
|
131 |
| - :class="'dropDownActions border-transparent'" |
132 | 122 | @action="rowActionsHandler"
|
133 | 123 | />
|
134 | 124 | </TableCell>
|
@@ -259,6 +249,7 @@ import {ref, computed, onMounted, watch, onBeforeUnmount} from 'vue';
|
259 | 249 | import {t} from '@/utils/i18n';
|
260 | 250 | import {useModal} from '@/composables/useModal';
|
261 | 251 | import DropdownActions from '@/components/DropdownActions/DropdownActions.vue';
|
| 252 | +import FieldText from '@/components/Form/fields/FieldText.vue'; |
262 | 253 | import FieldError from '@/components/Form/FieldError.vue';
|
263 | 254 | import FieldAffiliationsRorAutoSuggest from '@/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue';
|
264 | 255 | import Icon from '@/components/Icon/Icon.vue';
|
@@ -343,17 +334,11 @@ const {fetch: postRorObject} = useFetch(apiUrl.value, {
|
343 | 334 | body: rorObjectToBeUpdated,
|
344 | 335 | });
|
345 | 336 |
|
346 |
| -computed(() => { |
| 337 | +const errors = computed(() => { |
347 | 338 | if (!Object.keys(props.allErrors).includes(props.name)) {
|
348 | 339 | return [];
|
349 | 340 | }
|
350 |
| - let errors = props.allErrors[props.name]; |
351 |
| - if (props.isMultilingual && Object.keys(errors).includes(props.localeKey)) { |
352 |
| - return errors[props.localeKey]; |
353 |
| - } else if (!props.isMultilingual) { |
354 |
| - return errors; |
355 |
| - } |
356 |
| - return []; |
| 341 | + return props.allErrors[props.name]; |
357 | 342 | });
|
358 | 343 |
|
359 | 344 | watch(
|
@@ -444,7 +429,7 @@ const rowActionsArgs = function (index) {
|
444 | 429 | label: t('user.affiliations.translationActionsAriaLabel', {}),
|
445 | 430 | ariaLabel: t('user.affiliations.translationActionsAriaLabel', {}),
|
446 | 431 | direction: 'left',
|
447 |
| - displayAsEllipsis: true, |
| 432 | + buttonVariant: 'ellipsis', |
448 | 433 | };
|
449 | 434 | };
|
450 | 435 |
|
@@ -503,6 +488,21 @@ function deleteRow(index) {
|
503 | 488 | });
|
504 | 489 | }
|
505 | 490 |
|
| 491 | +function updateAffiliationName(affiliationIndex, locale, value) { |
| 492 | + currentValue.value = currentValue.value.map((affiliation, index) => { |
| 493 | + if (index !== affiliationIndex) { |
| 494 | + return affiliation; |
| 495 | + } |
| 496 | + return { |
| 497 | + ...affiliation, |
| 498 | + name: { |
| 499 | + ...affiliation.name, |
| 500 | + [locale]: value, |
| 501 | + }, |
| 502 | + }; |
| 503 | + }); |
| 504 | +} |
| 505 | +
|
506 | 506 | // helper methods
|
507 | 507 |
|
508 | 508 | function makeCurrentValueCompatible() {
|
|
0 commit comments