Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show primary tag error on touch or submit #4040

Merged
Merged
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
26 changes: 17 additions & 9 deletions ui/v2.5/src/components/Scenes/SceneDetails/SceneMarkerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {
useSceneMarkerDestroy,
} from "src/core/StashService";
import { DurationInput } from "src/components/Shared/DurationInput";
import { TagSelect, MarkerTitleSuggest } from "src/components/Shared/Select";
import {
TagSelect,
MarkerTitleSuggest,
SelectObject,
} from "src/components/Shared/Select";
import { getPlayerPosition } from "src/components/ScenePlayer/util";
import { useToast } from "src/hooks/Toast";
import isEqual from "lodash-es/isEqual";

interface ISceneMarkerForm {
sceneID: string;
Expand Down Expand Up @@ -97,6 +100,11 @@ export const SceneMarkerForm: React.FC<ISceneMarkerForm> = ({
}
}

async function onSetPrimaryTagID(tags: SelectObject[]) {
await formik.setFieldValue("primary_tag_id", tags[0]?.id);
await formik.setFieldTouched("primary_tag_id", true);
}

const primaryTagId = formik.values.primary_tag_id;

return (
Expand All @@ -119,16 +127,16 @@ export const SceneMarkerForm: React.FC<ISceneMarkerForm> = ({
</Form.Label>
<div className="col-sm-4 col-md-6 col-xl-12 mb-3 mb-sm-0 mb-xl-3">
<TagSelect
onSelect={(tags) =>
formik.setFieldValue("primary_tag_id", tags[0]?.id)
}
onSelect={onSetPrimaryTagID}
ids={primaryTagId ? [primaryTagId] : []}
noSelectionString="Select/create tag..."
hoverPlacement="right"
/>
<Form.Control.Feedback type="invalid">
{formik.errors.primary_tag_id}
</Form.Control.Feedback>
{formik.touched.primary_tag_id && (
<Form.Control.Feedback type="invalid">
{formik.errors.primary_tag_id}
</Form.Control.Feedback>
)}
</div>
<div className="col-sm-5 col-md-4 col-xl-12">
<div className="row">
Expand Down Expand Up @@ -175,7 +183,7 @@ export const SceneMarkerForm: React.FC<ISceneMarkerForm> = ({
<div className="col d-flex">
<Button
variant="primary"
disabled={(!isNew && !formik.dirty) || !isEqual(formik.errors, {})}
disabled={!isNew && !formik.dirty}
onClick={() => formik.submitForm()}
>
<FormattedMessage id="actions.save" />
Expand Down
Loading