Skip to content

Commit

Permalink
update additionaltitles to use formfield value hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mirekys committed Nov 10, 2023
1 parent de348a3 commit a06ed3c
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import PropTypes from "prop-types";
import { Form } from "semantic-ui-react";
import { ArrayField, SelectField } from "react-invenio-forms";
import { i18next } from "@translations/docs_app/i18next";
import { I18nTextInputField, ArrayFieldItem } from "@js/oarepo_ui";
import {
I18nTextInputField,
ArrayFieldItem,
useDefaultLocale,
useFormFieldValue,
} from "@js/oarepo_ui";

const subtitleTypes = [
{ text: "Alternative title", value: "alternativeTitle" },
Expand All @@ -13,10 +18,23 @@ const subtitleTypes = [
];

export const AdditionalTitlesField = ({ fieldPath }) => {
const { defaultLocale } = useDefaultLocale();
const initialValueObj = {
title: {
value: "",
},
};
const { defaultNewValue } = useFormFieldValue({
defaultValue: defaultLocale,
fieldPath,
subValuesPath: "title.lang",
subValuesUnique: false,
});

return (
<ArrayField
addButtonLabel={i18next.t("Add additional title")}
defaultNewValue={{}}
defaultNewValue={defaultNewValue(initialValueObj)}
fieldPath={fieldPath}
label={i18next.t("Additional titles")}
labelIcon="pencil"
Expand Down

0 comments on commit a06ed3c

Please sign in to comment.