Skip to content

Commit

Permalink
Show primary tag error on touch or submit (stashapp#4040)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored and halkeye committed Sep 1, 2024
1 parent 5450b1f commit 8a8bd9e
Showing 1 changed file with 17 additions and 9 deletions.
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

0 comments on commit 8a8bd9e

Please sign in to comment.