Type Field "code"

default discord avatar
hasterisk
last month
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>


@muperdev

  • default discord avatar
    muperdev
    last month

    <script>


    (function(){


    console.log("do something")


    })()


    </script>



    this is the value you get?

  • default discord avatar
    hasterisk
    last month

    Yeah, that's my test value



    But am getting it as a string

  • default discord avatar
    muperdev
    last month

    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
    hasterisk
    last month
    image.png
  • default discord avatar
    muperdev
    last month

    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
    hasterisk
    last month

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

  • default discord avatar
    muperdev
    last month

    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/

    @hasterisk

  • default discord avatar
    hasterisk
    last month

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

    image.png
  • default discord avatar
    muperdev
    last month

    you want to put HTML in head tag?!

  • default discord avatar
    hasterisk
    last month

    the script tag is what i really want to put there



    @christian015

  • default discord avatar
    muperdev
    last month

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

  • default discord avatar
    hasterisk
    last month

    I dangerously added it to dev, seem to work



    Thanks man

  • default discord avatar
    muperdev
    last month

    great, you're most welcome

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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