Skip to content

Hotfix for issue 2014 #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controls/dynamicForm/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export class DynamicFormBase extends React.Component<
// Choice fields

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

if (field.fieldType === "Choice") {
field.stringValue = newValue.text;
field.stringValue = newValue? newValue.text:'';
}
if (field.fieldType === "MultiChoice") {
field.stringValue = newValue.join(';#');
Expand Down
39 changes: 39 additions & 0 deletions src/controls/dynamicForm/dynamicField/DropdownWithRemoveButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Dropdown, IconButton, IDropdownProps, IIconProps } from "@fluentui/react";
import React from "react";
import { useState } from "react";



export const DropdownWithRemoveButton = (props: IDropdownProps): JSX.Element => {
const [isEditing, setIsEditing] = useState(false);

const titleRendererWithRemoveButton: IDropdownProps["onRenderTitle"] = (options) => {
const iconStyles = {
root: { "font-size": '12px' }
};
const removeIcon: IIconProps = { iconName: 'Clear', styles: iconStyles };
return (
<div>
<span><span>{options[0].text}</span>
{
isEditing && <IconButton onClick={(e) => {
props.onChange(null, null);
e.stopPropagation();
}} iconProps={removeIcon} title="Remove" ariaLabel="Remove" />
}
</span>
</div>
);
};

return (
<Dropdown
{...props}
onRenderTitle={titleRendererWithRemoveButton}
onMouseLeave={(e) => { setIsEditing(false); if (props.onMouseLeave) { props.onMouseLeave(e) }}}
onFocus={(e) => { setIsEditing(true); if (props.onFocus) { props.onFocus(e) } }}
/>

)

}
3 changes: 2 additions & 1 deletion src/controls/dynamicForm/dynamicField/DynamicField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ModernTaxonomyPicker } from '../../modernTaxonomyPicker';
import { classNamesFunction, IProcessedStyleSet, styled, ChoiceGroup, IChoiceGroupOption } from '@fluentui/react';
import { getFluentUIThemeOrDefault } from '../../../common/utilities/ThemeUtility';
import { getFieldStyles } from './DynamicField.styles';
import { DropdownWithRemoveButton } from './DropdownWithRemoveButton';

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

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

// If the choiceType is dropdown
if (choiceType === ChoiceFieldFormatType.Dropdown) {
choiceControl = <Dropdown
choiceControl = <DropdownWithRemoveButton
{...dropdownOptions}
defaultSelectedKey={valueToDisplay ? undefined : defaultValue}
selectedKey={typeof valueToDisplay === "object" ? valueToDisplay?.key : valueToDisplay}
Expand Down