Skip to content

Auto-Populate Fields #471

Answered by jacobsfletch
peniswafflexd asked this question in Q&A

You must be logged in to vote

Hey @peniswafflexd

Glad to hear of your successes so far. Fortunately, what you describe is a common feature and pretty simple to setup. Since you already have a custom field, you're half way there.

To read the current value of another field in your document, use the getDataByPath method from the useWatchForm hook. Just send it the name of the field your are looking for. In your case, this is probably title. Now you can format the href using this value, and render an anchor tag on the page.

To go the extra mile, you can also import Payload's CopyToClipboard component and enhance the user experience.

import React from 'react';
import { useWatchForm } from 'payload/components/forms';
import C…

Replies: 1 comment 4 replies

You must be logged in to vote
4 replies
@peniswafflexd

@jacobsfletch

@peniswafflexd

@jacobsfletch

Answer selected by jacobsfletch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants