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.

Type Field "code"

default discord avatar
hasterisklast year
13

I get the value return from

fields: [
    {
      name: "trackingCode",
      type: "code",
      required: true,
      admin: {
        language: "html",
      },
    },
  ]

which is a html script tag in my web app, the problem is that the return type is a string and not the code, i tried using JSON.parse but go error to retrieve the raw code



value passed:

<script>
  (function(){
      console.log("do something")
   })()
</script>


@599971721490989117
  • default discord avatar
    muperdevlast year

    <script>


    (function(){


    console.log("do something")


    })()


    </script>



    this is the value you get?

  • default discord avatar
    hasterisklast year

    Yeah, that's my test value



    But am getting it as a string

  • default discord avatar
    muperdevlast year

    can you try another value ?



    send me the log in the network or console if it's possible



    want to track down your problem

  • default discord avatar
    hasterisklast year
  • default discord avatar
    muperdevlast year

    ok now you don't want this value as string?



    I didn't get your point yet, that's why Im asking

  • default discord avatar
    hasterisklast year

    on the front end how can i use it, it being a string makes that difficult

  • default discord avatar
    muperdevlast year

    you should parse it in the dangeroussetinnerhtml



    it's a little bit tricky, but I'll send you the example now



    https://blog.logrocket.com/using-dangerouslysetinnerhtml-in-a-react-application/

    @524858632731492362
  • default discord avatar
    hasterisklast year

    Tried this, but the problem is i want to make that goes in the head tag which i pass like this

  • default discord avatar
    muperdevlast year

    you want to put HTML in head tag?!

  • default discord avatar
    hasterisklast year

    the script tag is what i really want to put there



    @406714846084726785
  • default discord avatar
    muperdevlast year

    you should add it as a child to open and close script tag

  • default discord avatar
    hasterisklast year

    I dangerously added it to dev, seem to work



    Thanks man

  • default discord avatar
    muperdevlast year

    great, you're most welcome

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.