From a6a1eb44b63378cd699794823401262c33d849d3 Mon Sep 17 00:00:00 2001 From: jp-96 Date: Thu, 24 Aug 2023 16:17:35 +0900 Subject: [PATCH 1/3] Update field_userenum.ts Data binding fails. https://github.com/microsoft/pxt/issues/9653 Console warning: Cannot set the dropdown's value to an unavailable option. Block type: radioMessageCode, Field name: MEMBER, Value: add1 --- pxtblocks/fields/field_userenum.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pxtblocks/fields/field_userenum.ts b/pxtblocks/fields/field_userenum.ts index f59871c8b694..e8ba915f9cae 100644 --- a/pxtblocks/fields/field_userenum.ts +++ b/pxtblocks/fields/field_userenum.ts @@ -21,6 +21,18 @@ 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_ && this.sourceBlock_.workspace) { + const options = this.sourceBlock_.workspace.getVariablesOfType(this.opts.name); + options.some(model => { + const [name, ] = parseName(model); + if (name == value) { + value = model.name + return true + } + return false + }); + } // 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 +181,4 @@ namespace pxtblockly { } return undefined; } -} \ No newline at end of file +} From 9a6f287caffa0c71761c6542afa4b2dd0a2760d5 Mon Sep 17 00:00:00 2001 From: jp-96 Date: Sat, 26 Aug 2023 00:48:18 +0900 Subject: [PATCH 2/3] Update pxtblocks/fields/field_userenum.ts Co-authored-by: Joey Wunderlich --- pxtblocks/fields/field_userenum.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxtblocks/fields/field_userenum.ts b/pxtblocks/fields/field_userenum.ts index e8ba915f9cae..1e7b9ca0f464 100644 --- a/pxtblocks/fields/field_userenum.ts +++ b/pxtblocks/fields/field_userenum.ts @@ -22,7 +22,7 @@ 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_ && this.sourceBlock_.workspace) { + if (this.sourceBlock_?.workspace) { const options = this.sourceBlock_.workspace.getVariablesOfType(this.opts.name); options.some(model => { const [name, ] = parseName(model); From 0e2c369dbada50606833f5fbb72c586a5d6afb4b Mon Sep 17 00:00:00 2001 From: jp-96 Date: Sat, 26 Aug 2023 00:48:34 +0900 Subject: [PATCH 3/3] Update pxtblocks/fields/field_userenum.ts Co-authored-by: Joey Wunderlich --- pxtblocks/fields/field_userenum.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pxtblocks/fields/field_userenum.ts b/pxtblocks/fields/field_userenum.ts index 1e7b9ca0f464..e1e3ff3ef403 100644 --- a/pxtblocks/fields/field_userenum.ts +++ b/pxtblocks/fields/field_userenum.ts @@ -24,14 +24,13 @@ namespace pxtblockly { // 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); - options.some(model => { + const matchingOption = options.find(model => { const [name, ] = parseName(model); - if (name == value) { - value = model.name - return true - } - return false + 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();