Skip to content

Auto-Populate Fields #471

Answered by jacobsfletch
peniswafflexd asked this question in Q&A
Discussion options

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

Comment options

You must be logged in to vote
4 replies
@peniswafflexd
Comment options

@jacobsfletch
Comment options

@peniswafflexd
Comment options

@jacobsfletch
Comment options

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