diff --git a/pxtblocks/fields/field_userenum.ts b/pxtblocks/fields/field_userenum.ts index f59871c8b694..e1e3ff3ef403 100644 --- a/pxtblocks/fields/field_userenum.ts +++ b/pxtblocks/fields/field_userenum.ts @@ -21,6 +21,17 @@ namespace pxtblockly { } doClassValidation_(value: any) { + // The format of the name is 10mem where "10" is the value and "mem" is the enum member + if (this.sourceBlock_?.workspace) { + const options = this.sourceBlock_.workspace.getVariablesOfType(this.opts.name); + const matchingOption = options.find(model => { + const [name, ] = parseName(model); + return name === value; + }); + if (matchingOption) { + value = matchingOption.name; + } + } // update cached option list when adding a new kind if (this.opts?.initialMembers && !this.opts.initialMembers.find(el => el == value)) this.getOptions(); return super.doClassValidation_(value); @@ -169,4 +180,4 @@ namespace pxtblockly { } return undefined; } -} \ No newline at end of file +}