# How to set fields in \`Editor\`/\`EditorWebView\`

**URL:** <https://forums.ankiweb.net/t/how-to-set-fields-in-editor-editorwebview/19594>\
**Category:** Add-ons\
**Created:** [April 30, 2022, 4:32am UTC](https://forums.ankiweb.net/t/how-to-set-fields-in-editor-editorwebview/19594 "2022-04-30T04:32:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94524639](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon94524639](https://forums.ankiweb.net/u/anon94524639)\
**Post date:** [April 30, 2022, 4:32am UTC](https://forums.ankiweb.net/t/how-to-set-fields-in-editor-editorwebview/19594/1 "2022-04-30T04:32:23Z")

</div>

I’m making a button in the `AddCards` menu, that pulls in data from an online dictionary, and sets the fields accordingly.

I found the `Editor` class, but it seems very complicated with the fields themselves in JS. I couldn’t find any methods to edit the fields programatically in that file.

Would I need to run my own JS similar to how `loadNote` works? Is there some way to sync the note object with the JS, edit it, then send it back to JS?

I’m not really sure how to do this (this is my first addon) so I’d appreciate the help 🙂

---

<div class="post-metadata">

**Author:** ![kleinerpirat](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kleinerpirat/32/19863_2.png) [@kleinerpirat](https://forums.ankiweb.net/u/kleinerpirat)\
**Post date:** [April 30, 2022, 7:30am UTC](https://forums.ankiweb.net/t/how-to-set-fields-in-editor-editorwebview/19594/3 "2022-04-30T07:30:58Z")

</div>

You can access field content with `note.items()`. It returns a list of key-value pairs, so you can read each field’s content with `value` and decide if changes should be made.

After you’ve made changes, call `note.flush()` to write them to the database (except in add mode).

```python
def write_field_contents(note, contents : [str], addMode=False):
    for i, (key, value) in enumerate(note.items()):
        note[key] = contents[i]

    if not addMode:
        note.flush()

```
