Skip to content

Commit cc22428

Browse files
authored
Merge pull request #2016 from wuxiaojun514/2014
Hotfix for issue 2014
2 parents 05b5f8f + 3168597 commit cc22428

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ export class DynamicFormBase extends React.Component<
470470
// Choice fields
471471

472472
if (fieldType === "Choice") {
473-
objects[fieldcolumnInternalName] = field.newValue.key;
473+
objects[fieldcolumnInternalName] = field.newValue?field.newValue.key:null
474474
}
475475
if (fieldType === "MultiChoice") {
476476
objects[fieldcolumnInternalName] = { results: field.newValue };
@@ -781,7 +781,7 @@ export class DynamicFormBase extends React.Component<
781781
// Store string values for various field types
782782

783783
if (field.fieldType === "Choice") {
784-
field.stringValue = newValue.text;
784+
field.stringValue = newValue? newValue.text:'';
785785
}
786786
if (field.fieldType === "MultiChoice") {
787787
field.stringValue = newValue.join(';#');
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Dropdown, IconButton, IDropdownProps, IIconProps } from "@fluentui/react";
2+
import React from "react";
3+
import { useState } from "react";
4+
5+
6+
7+
export const DropdownWithRemoveButton = (props: IDropdownProps): JSX.Element => {
8+
const [isEditing, setIsEditing] = useState(false);
9+
10+
const titleRendererWithRemoveButton: IDropdownProps["onRenderTitle"] = (options) => {
11+
const iconStyles = {
12+
root: { "font-size": '12px' }
13+
};
14+
const removeIcon: IIconProps = { iconName: 'Clear', styles: iconStyles };
15+
return (
16+
<div>
17+
<span><span>{options[0].text}</span>
18+
{
19+
isEditing && <IconButton onClick={(e) => {
20+
props.onChange(null, null);
21+
e.stopPropagation();
22+
}} iconProps={removeIcon} title="Remove" ariaLabel="Remove" />
23+
}
24+
</span>
25+
</div>
26+
);
27+
};
28+
29+
return (
30+
<Dropdown
31+
{...props}
32+
onRenderTitle={titleRendererWithRemoveButton}
33+
onMouseLeave={(e) => { setIsEditing(false); if (props.onMouseLeave) { props.onMouseLeave(e) }}}
34+
onFocus={(e) => { setIsEditing(true); if (props.onFocus) { props.onFocus(e) } }}
35+
/>
36+
37+
)
38+
39+
}

src/controls/dynamicForm/dynamicField/DynamicField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ModernTaxonomyPicker } from '../../modernTaxonomyPicker';
2626
import { classNamesFunction, IProcessedStyleSet, styled, ChoiceGroup, IChoiceGroupOption } from '@fluentui/react';
2727
import { getFluentUIThemeOrDefault } from '../../../common/utilities/ThemeUtility';
2828
import { getFieldStyles } from './DynamicField.styles';
29+
import { DropdownWithRemoveButton } from './DropdownWithRemoveButton';
2930

3031
const getClassNames = classNamesFunction<IDynamicFieldStyleProps, IDynamicFieldStyles>();
3132

@@ -195,7 +196,7 @@ export class DynamicFieldBase extends React.Component<IDynamicFieldProps, IDynam
195196

196197
// If the choiceType is dropdown
197198
if (choiceType === ChoiceFieldFormatType.Dropdown) {
198-
choiceControl = <Dropdown
199+
choiceControl = <DropdownWithRemoveButton
199200
{...dropdownOptions}
200201
defaultSelectedKey={valueToDisplay ? undefined : defaultValue}
201202
selectedKey={typeof valueToDisplay === "object" ? valueToDisplay?.key : valueToDisplay}

0 commit comments

Comments
 (0)