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

SlugEditor: Allow option to make SlugEditor not track any title fields #1538

Open
sharanrprasad opened this issue Nov 9, 2023 · 1 comment
Labels
stale Used to mark when there was no activity for a set period of time

Comments

@sharanrprasad
Copy link

sharanrprasad commented Nov 9, 2023

We want to build a custom Contentful app using SlugEditor which attaches today's date to the slug. This ensures that all the new content we are publishing has unique url and is not equal to any previously deleted content.

When using the SlugEditor in a custom app, the value we write to it keeps getting overwritten by the default slug generated by the SlugEditor based on the title field in that entry.

This is our code -

const Field = () => {
  const sdk = useSDK<FieldAppSDK>();
  useAutoResizer();

 useEffect(() => {
    const updateSlugField = async (value: string) => {
      if (sdk.entry.getSys().firstPublishedAt) return;
      const currentDate = new Date();
      const year = currentDate.getFullYear();
      const month = String(currentDate.getMonth() + 1).padStart(2, '0');
      const day = String(currentDate.getDate()).padStart(2, '0');
      const slugWithPrefix = `${year}${month}${day}-${customSlugify(value)}`;
      await sdk.field.setValue(slugWithPrefix);
    };

    const titleField = sdk.entry.fields[sdk.contentType.displayField];

    const titleFieldListener = titleField.onValueChanged(updateSlugField);

    (async () => {
      await updateSlugField(titleField.getValue());
    })();

    return titleFieldListener;
  }, [sdk]);

  return (
    <div>
      <SlugEditor
        isInitiallyDisabled={true}
        parameters={{ instance: { trackingFieldId: undefined } }}
        field={sdk.field}
        baseSdk={sdk}
      />
    </div>
  );
};

Can you please either allow us to disable the tracking title field option or pass a custom slugify method.

@sharanrprasad sharanrprasad changed the title Slug Editor: Allow option of SlugEditor not tracking any title fields Slug Editor: Allow option to make SlugEditor not track any title fields Nov 9, 2023
@sharanrprasad sharanrprasad changed the title Slug Editor: Allow option to make SlugEditor not track any title fields SlugEditor: Allow option to make SlugEditor not track any title fields Nov 9, 2023
Copy link

github-actions bot commented Jan 3, 2024

Marking issue as stale since there was no activity for 30 days

@github-actions github-actions bot added the stale Used to mark when there was no activity for a set period of time label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Used to mark when there was no activity for a set period of time
Projects
None yet
Development

No branches or pull requests

1 participant