async await for default value

async await for default value

aazwaraazwar Posts: 1Questions: 1Answers: 0

I've tried async await for default value, but it doesn't work

    { label: 'Number',  name: 'number',
      async def() {
        let resp = await fetch('{{@BASE}}/ajax/reference/new-id?type=' + type);
        return resp;
      }  
    },

The corresponding input in the editor contains '[object Promise]'

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    Hi,

    The field.def option does not accept a promise in return. What you would need to do is use initCreate to trigger your Ajax request and then write to field().val() to set the field when it is complete.

    Allan

This discussion has been closed.