Skip to content

Commit

Permalink
Fix 2 issues (EnumKey length = 1) + Loading same widget multiple times
Browse files Browse the repository at this point in the history
Fix for Enumeration keys with a length of 1 (these were ignored because of length > 1 instead of length >=1)
Fix for label "for" and input id's where the widget was loaded more than once on a page. These id's weren't unique anymore. Fixed by adding the widget-id to these for / id attributes.
  • Loading branch information
stephanbruijnis committed Feb 21, 2023
1 parent 15aeba4 commit 25ffb1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
@@ -1,9 +1,9 @@
{
"name": "multiselectenum",
"widgetName": "MultiSelectEnum",
"version": "1.0.0",
"version": "1.1.1",
"description": "Select multiple enumeration values",
"copyright": "2021 Stephan Bruijnis Consultancy",
"copyright": "2023 Stephan Bruijnis Consultancy",
"author": "Stephan Bruijnis",
"engines": {
"node": ">=12"
Expand Down
9 changes: 6 additions & 3 deletions src/MultiSelectEnum.tsx
Expand Up @@ -18,11 +18,13 @@ class MultiSelectEnum extends Component<MultiSelectEnumContainerProps> {
render(): ReactNode {
// The enumeration labels (captions)
const captions = this.universe.map(name => this.props.enumAttribute.formatter.format(name)); // labels (name of enum)
console.debug("enumeration captions: " + captions);
//console.debug("enumeration captions: " + captions);

// All possible enumeration values (keys)
const universe = this.universe
console.debug("universe: " + universe);
//console.debug("universe: " + universe);
//console.debug("id:" + this.props.id);
//console.debug("name:" + this.props.name);

// Current value of the string attribute that contains the comma separate values (enumeration keys)
const valueStr = this.props.enumAttribute_str.value || "";
Expand Down Expand Up @@ -61,6 +63,7 @@ class MultiSelectEnum extends Component<MultiSelectEnumContainerProps> {
checkedState={checkedState}
onUpdate={this.onUpdateHandle}
disabled={this.isReadOnly()}
widgetId={this.props.id}
/>
);
}
Expand All @@ -76,7 +79,7 @@ class MultiSelectEnum extends Component<MultiSelectEnumContainerProps> {
var res = valueStr.split(',').filter(s => s !== value).join(',');
this.props.enumAttribute_str.setValue(res);
} else {
if (valueStr.length > 1) {
if (valueStr.length >= 1) {
var res = valueStr + ',' + value;
}
else {
Expand Down
5 changes: 3 additions & 2 deletions src/components/CheckboxItem.tsx
Expand Up @@ -4,6 +4,7 @@ export interface InputProps {
className?: string;
label: string;
enumKey: string;
widgetId: string;
index?: number;
style?: CSSProperties;
tabIndex?: number;
Expand All @@ -24,13 +25,13 @@ export class CheckboxItem extends Component<InputProps> {
<input
type="Checkbox"
value={this.props.enumKey}
id={this.props.enumKey}
id={this.props.widgetId+"."+this.props.enumKey}
defaultChecked={this.props.checkedState}
checked={this.props.checkedState}
onChange={(e) => { this.onChangeHandle(e); }}
disabled={this.props.disabled}
/>
<label htmlFor={this.props.enumKey} className={this.props.checkedState ? "checked" : ""}>
<label htmlFor={this.props.widgetId+"."+this.props.enumKey} className={this.props.checkedState ? "checked" : ""}>
{this.props.label}
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="MultiSelectEnum" version="1.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="MultiSelectEnum" version="1.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="MultiSelectEnum.xml"/>
</widgetFiles>
Expand Down

0 comments on commit 25ffb1d

Please sign in to comment.