Can't seem to edit fields before submission

Can't seem to edit fields before submission

1ticket1ticket Posts: 11Questions: 8Answers: 1

I tried both

        .on('initSubmit', async function( e, a ) {
            map = await teamNameMap()
            team_id = editor.field('system_name').val()
            team_name = map[team_id]
            editor.field('subsystem').val(team_id)
            editor.field('system_name').val(team_name)
            editor.field('api_token').val(Math.random(1) * 100)
        })

and

        .on('preSubmit', async function( e, o, a ) {
            console.log(e)
            data = o.data[Object.keys(o.data)[0]]
            data.subsystem = data.system_name
            let map = (await teamNameMap())
            data.system_name = map[data.subsystem]
            data.api_token = "cheese"
            o.data = data
        })

and neither seem to be affecting the data that gets sent to the server, afaics from dev console

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    You are using async functions but Editor does not currently await events. Editor 1.8 is going to introduce that ability (specifically to return a promise from the event callback).

    Until 1.8 (which isn't far away) you would need to change your code to be sync rather than async.

    Allan

This discussion has been closed.