Relationship add new with default

default discord avatar
martin.rahbeklast year
3

When creating a new item through a relationship filed, and the relationship only can contain items with a category.



    {
      name: "wheels",
      type: "relationship",
      filterOptions: (args) => {

        return { category: { equals: "wheels" } };
      },
      relationTo: ["spare-parts"],
    },


Can I set the default value for the new relationship item "wheels.category" in the remote collection to "wheels" when added through a relationship?



My solution was to disable edit and create for the relationship field.

  • default discord avatar
    dnl.krmrlast year

    Hi @martin.rahbek I tried your code.


    But how did you set the default value?

  • default discord avatar
    martin.rahbeklast year

    defaultValue: () => {


            // query the default and return it here


            return {


              value: "53673f577e92b8ea049d3ca5",


              relationTo: "spare-parts",


            };


          },

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.