Railsでいうnested attributesみたいなやつ
{
"title" => "title dayo",
"body" => "body dayo",
"tag_attributes" => {
"0" => { "name" => "hoge" },
"1" => { "name" => "fuga"}
}
}
Yup.lazyとlodashのmapValuesを使いました。
import * as Yup from "yup";
import mapValues from "lodash.mapvalues";
interface Form {
title: string;
body: string;
tag_attributes: {
[key: string]: {
name: number;
};
};
}
const validationSchema = Yup.object().shape({
title: Yup.string(),
body: Yup.string(),
tag_attributes: Yup.lazy<object>(obj =>
Yup.object(
mapValues(obj, () =>
Yup.object().shape({
name: Yup.string()
})
)
)
)
});
以上です