|
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 |
| - '-' + |
101 |
| - affiliationNameLocale |
102 |
| - " |
103 |
| - v-model="affiliation.name[affiliationNameLocale]" |
104 |
| - :name=" |
105 |
| - 'contributors-affiliations-' + |
106 |
| - affiliationIndex + |
107 |
| - '-' + |
| 92 | + <FieldText |
| 93 | + :label="getTextFieldLabel(affiliationNameLocale)" |
| 94 | + :value="affiliation.name[affiliationNameLocale]" |
| 95 | + name="name" |
| 96 | + :all-errors="{ |
| 97 | + name: errors?.[affiliationIndex]?.name?.[ |
108 | 98 | affiliationNameLocale
|
109 |
| - " |
110 |
| - class="pkpFormField__input pkpFormField--text__input" |
111 |
| - type="text" |
112 |
| - :aria-invalid="false" |
113 |
| - /> |
114 |
| - </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 | + /> |
115 | 113 | </div>
|
116 | 114 | </div>
|
117 | 115 | </div>
|
|
121 | 119 | <DropdownActions
|
122 | 120 | v-if="!(affiliationIndex === indexEditMode)"
|
123 | 121 | v-bind="rowActionsArgs(affiliationIndex)"
|
124 |
| - :class="'dropDownActions border-transparent'" |
125 | 122 | @action="rowActionsHandler"
|
126 | 123 | />
|
127 | 124 | </TableCell>
|
@@ -312,17 +309,11 @@ const {fetch: postRorObject} = useFetch(apiUrl.value, {
|
312 | 309 | body: rorObjectToBeUpdated,
|
313 | 310 | });
|
314 | 311 |
|
315 |
| -computed(() => { |
| 312 | +const errors = computed(() => { |
316 | 313 | if (!Object.keys(props.allErrors).includes(props.name)) {
|
317 | 314 | return [];
|
318 | 315 | }
|
319 |
| - let errors = props.allErrors[props.name]; |
320 |
| - if (props.isMultilingual && Object.keys(errors).includes(props.localeKey)) { |
321 |
| - return errors[props.localeKey]; |
322 |
| - } else if (!props.isMultilingual) { |
323 |
| - return errors; |
324 |
| - } |
325 |
| - return []; |
| 316 | + return props.allErrors[props.name]; |
326 | 317 | });
|
327 | 318 |
|
328 | 319 | // new affiliation form
|
@@ -417,7 +408,7 @@ const rowActionsArgs = function (index) {
|
417 | 408 | label: t('user.affiliations.translationActionsAriaLabel', {}),
|
418 | 409 | ariaLabel: t('user.affiliations.translationActionsAriaLabel', {}),
|
419 | 410 | direction: 'left',
|
420 |
| - displayAsEllipsis: true, |
| 411 | + buttonVariant: 'ellipsis', |
421 | 412 | };
|
422 | 413 | };
|
423 | 414 |
|
@@ -476,6 +467,21 @@ function deleteRow(index) {
|
476 | 467 | });
|
477 | 468 | }
|
478 | 469 |
|
| 470 | +function updateAffiliationName(affiliationIndex, locale, value) { |
| 471 | + currentValue.value = currentValue.value.map((affiliation, index) => { |
| 472 | + if (index !== affiliationIndex) { |
| 473 | + return affiliation; |
| 474 | + } |
| 475 | + return { |
| 476 | + ...affiliation, |
| 477 | + name: { |
| 478 | + ...affiliation.name, |
| 479 | + [locale]: value, |
| 480 | + }, |
| 481 | + }; |
| 482 | + }); |
| 483 | +} |
| 484 | +
|
479 | 485 | // helper methods
|
480 | 486 |
|
481 | 487 | function getLocaleDisplayName(locale) {
|
|
0 commit comments