Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

duplicate page not working

default discord avatar
shubham2768542 years ago
33

when i click on duplicate button its giving me error.



"message":"subpages validation failed: categoryName:

62

is not a valid enum value for path

categoryName

."}]



I have attached my code for whatever i have did as of now.

  • discord user avatar
    jarrod_not_jared
    2 years ago

    could you make a minimally reproducible example to share? If this is a bug that would allow us to fix it more promptly. You can start from

    categoryName

    and work backwards when throwing together a new collection with a similar shape, but define all of your fields in one file so others can just paste it into their environment to test it once you can reproduce it with minimal fields 👍

  • default discord avatar
    shubham2768542 years ago

    all of fields are defined in a same file

    @281120856527077378
  • discord user avatar
    jarrod_not_jared
    2 years ago

    You are importing quite a bit of code that lives outside of this file

    @1041992215632805888
  • default discord avatar
    jessrynkar2 years ago

    It seems to be coming from your

    beforeValidate

    hook but like Jarrod said we need the relevant files to properly dig into this - we are unable to hit that fetch request without your index.php and likely other files.

  • default discord avatar
    shubham2768542 years ago

    do you want data from api response of this index.php api call ?



    [


    {


    id: "67",


    category_code: "eLearning",


    title: "eLearning",


    slug: "portfolio/oneclick-portfolio",


    description: "eLearning",


    portfolio_type: "1",


    portfolio_file_path: "ddssdvddfdfgvfgefg",


    file_name: "",


    status: "1",


    created_by: "Demo User 2"


    },


    ]

  • default discord avatar
    jessrynkar2 years ago
    @1041992215632805888

    apologies for the delay - are you still experiencing this issue?

  • default discord avatar
    shubham2768542 years ago

    yes

    @854377910689202256

    https://docs.google.com/document/d/1JYuIX7RXVhUslCm5oRXJKj7FY2ds7r-1VIAhkn28CCM/edit

    @854377910689202256

    here is the problem description that i am getting. hope it helps you understand issue that i am facing.

  • discord user avatar
    jarrod_not_jared
    2 years ago
    @1041992215632805888

    The payload config is meant to be static. I think what you should instead do is create a custom field, possibly using the new

    json

    field type. You would render a custom select component that would fetch data from your endpoint and when the user submits, you add the data to the json field.

  • default discord avatar
    bhavikak.2 years ago
    @281120856527077378

    can you share me small example of custom select field with dynamic options or any other reference that related to it.

  • default discord avatar
    remy_902 years ago

    Does this mean I can't reference data from one source (i.e. text input) and present it in a dropdown? More info on my scenario:

    https://discord.com/channels/967097582721572934/1072241616917643454/1072241616917643454
  • default discord avatar
    bhavikak.2 years ago

    Hiii

    @536888652257558538

    i'm want to render data in a select menu using custom select field



    i tried from this

    https://payloadcms.com/docs/admin/components#fields:~:text=%7D%3B-,Field%20Component,-When%20writing%20your

    but it doesn't store selected value in api

  • default discord avatar
    remy_902 years ago

    I managed to store the selected value with useFormFields -

    https://payloadcms.com/docs/admin/hooks#useformfields

    . Hope that helps

  • default discord avatar
    bhavikak.2 years ago

    thanks

    @536888652257558538

    i'll try it.



    hello

    @536888652257558538

    i tried but didn't work



    this is the my code can you help me

  • default discord avatar
    remy_902 years ago
    useFormFields

    , not

    useField

    const { fields, dispatch } = useFormFields(([fields, dispatch]) => ({ fields, dispatch }))
    console.log('fields', JSON.stringify(fields))
  • default discord avatar
    bhavikak.2 years ago

    hii

    @536888652257558538

    still not working it's not storing selected value even it's not create a field





  • default discord avatar
    remy_902 years ago

    Well the rest is just react:


      const handleChange = (e: ChangeEvent<HTMLSelectElement>, path: string) => {
        setSelectedOption(e.target.value) // React.useState
      };


    <select value={selectedOption} onChange={(e) => handleChange(e, path)}>
      <option>...</option>
    </select>


    Obviously I can't see what's happening in your reducer but using React.useState will suffice for setting the selected value in the example I've provided. I'm assuming data.fields contains the values you're expecting?

  • default discord avatar
    bhavikak.2 years ago

    data.fields give me the all fields data.



    it store only in a state right?



    is it store into the api?

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Hey

    @1043125033519820902

    ! You should change your field type from

    ui

    to

    text

    🙂



    As you have noticed, ui fields

    do not

    store their data in the DB. So you will want to use a field type that does, i.e. text. You can leave the rest of your config as is, using the custom component that you created!

  • default discord avatar
    bhavikak.2 years ago

    okay

    @281120856527077378

    i'll try



    so i need to change only type?

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Yeah, and personally I think you could get away with using

    useField

    hook, and passing the path from props to that hook and using the

    setValue

    function to set the value of the field instead of the useFormFields

  • default discord avatar
    bhavikak.2 years ago

    wohooo it's working with useFormField as well so i need to changed with usefield



    thanks a lot

    @281120856527077378

    @536888652257558538

    🙌

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Absolutely, maybe I'll make a vid on custom components like the one you made 🤔

  • default discord avatar
    bhavikak.2 years ago

    yes, you can🤘



    hii

    @281120856527077378

    when i select the item it's not enable publish button



  • discord user avatar
    jarrod_not_jared
    2 years ago

    Can you log Form state for me? Using useFormFields?

  • default discord avatar
    bhavikak.2 years ago

    yaa



  • default discord avatar
    remy_902 years ago

    This is also the case for me. It persists in draft saves but doesn't trigger a change

  • discord user avatar
    jarrod_not_jared
    2 years ago

    And just to clarify, you are both using

    useField

    ?

  • default discord avatar
    remy_902 years ago

    I haven't updated mine from

    useFormField

    but i'm happy to follow along for

    @1043125033519820902

    's issue.

  • default discord avatar
    bhavikak.2 years ago

    yes

    @281120856527077378

    i'm use useFormField



    nope

  • discord user avatar
    jarrod_not_jared
    2 years ago
    @1043125033519820902

    can you use useField instead?



    Otherwise

    useForm

    exposes a

    setModified

    function that you can use to set the form as modified

  • default discord avatar
    bhavikak.2 years ago

    i tried with usefield as well but it's not save my selected option



    this is the my code



    hello

    @281120856527077378

    i'm waiting for your respone.

  • default discord avatar
    remy_902 years ago

    I think Jarrod wants you to convert to

    useField

    first



    When I get to reimplementing this, I'll create a new thread, as we're quite far from the original issue.

  • default discord avatar
    bhavikak.2 years ago

    hii

    @536888652257558538

    i tried it but it's not store value into the colliction api



    hello

    @536888652257558538

    my functionality is still pending can you suggest how i complete it using useField

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.