1
1
import '@pnp/sp/folders' ;
2
- import { sp } from '@pnp/sp/presets/all' ;
2
+ import { ChoiceFieldFormatType , sp } from '@pnp/sp/presets/all' ;
3
3
import '@pnp/sp/webs' ;
4
4
import * as strings from 'ControlStrings' ;
5
5
import { ActionButton } from '@fluentui/react/lib/Button' ;
@@ -23,11 +23,10 @@ import { IDynamicFieldProps, IDynamicFieldStyleProps, IDynamicFieldStyles } from
23
23
import { IDynamicFieldState } from './IDynamicFieldState' ;
24
24
import CurrencyMap from "../CurrencyMap" ;
25
25
import { ModernTaxonomyPicker } from '../../modernTaxonomyPicker' ;
26
- import { classNamesFunction , IProcessedStyleSet , styled } from '@fluentui/react' ;
26
+ import { classNamesFunction , IProcessedStyleSet , styled , ChoiceGroup , IChoiceGroupOption } from '@fluentui/react' ;
27
27
import { getFluentUIThemeOrDefault } from '../../../common/utilities/ThemeUtility' ;
28
28
import { getFieldStyles } from './DynamicField.styles' ;
29
29
30
-
31
30
const getClassNames = classNamesFunction < IDynamicFieldStyleProps , IDynamicFieldStyles > ( ) ;
32
31
33
32
export class DynamicFieldBase extends React . Component < IDynamicFieldProps , IDynamicFieldState > {
@@ -95,6 +94,7 @@ export class DynamicFieldBase extends React.Component<IDynamicFieldProps, IDynam
95
94
itemsQueryCountLimit,
96
95
customIcon,
97
96
orderBy,
97
+ choiceType,
98
98
useModernTaxonomyPickerControl
99
99
} = this . props ;
100
100
@@ -190,22 +190,50 @@ export class DynamicFieldBase extends React.Component<IDynamicFieldProps, IDynam
190
190
</ div > ;
191
191
}
192
192
193
- case 'Choice' :
194
- return < div className = { styles . fieldContainer } >
195
- < div className = { `${ styles . labelContainer } ${ styles . titleContainer } ` } >
196
- < Icon className = { styles . fieldIcon } iconName = { customIcon ?? "CheckMark" } />
197
- { labelEl }
198
- </ div >
199
- < Dropdown
193
+ case 'Choice' : {
194
+ let choiceControl : JSX . Element = undefined ;
195
+
196
+ // If the choiceType is dropdown
197
+ if ( choiceType === ChoiceFieldFormatType . Dropdown ) {
198
+ choiceControl = < Dropdown
200
199
{ ...dropdownOptions }
201
200
defaultSelectedKey = { valueToDisplay ? undefined : defaultValue }
202
201
selectedKey = { typeof valueToDisplay === "object" ? valueToDisplay ?. key : valueToDisplay }
203
202
onChange = { ( e , option ) => { this . onChange ( option , true ) ; } }
204
203
onBlur = { this . onBlur }
205
- errorMessage = { errorText } />
204
+ errorMessage = { errorText } /> ;
205
+ }
206
+ // If the choiceType is radio buttons
207
+ else {
208
+ // Parse options into radio buttons
209
+ const optionsGroup : IChoiceGroupOption [ ] =
210
+ options . map ( ( option ) => {
211
+ return {
212
+ key : option . key . toString ( ) ,
213
+ text : option . text ,
214
+ checked : option . key . toString ( ) === valueToDisplay
215
+ } ;
216
+ } ) ;
217
+
218
+ // Create radio group
219
+ choiceControl = < ChoiceGroup
220
+ defaultSelectedKey = { valueToDisplay ? undefined : defaultValue }
221
+ selectedKey = { typeof valueToDisplay === "object" ? valueToDisplay ?. key : valueToDisplay }
222
+ options = { optionsGroup }
223
+ onChange = { ( e , option ) => { this . onChange ( option , true ) ; } }
224
+ disabled = { disabled }
225
+ /> ;
226
+ }
227
+
228
+ return < div className = { styles . fieldContainer } >
229
+ < div className = { `${ styles . labelContainer } ${ styles . titleContainer } ` } >
230
+ < Icon className = { styles . fieldIcon } iconName = { customIcon ?? "CheckMark" } />
231
+ { labelEl }
232
+ </ div >
233
+ { choiceControl }
206
234
{ descriptionEl }
207
235
</ div > ;
208
-
236
+ }
209
237
case 'MultiChoice' :
210
238
return < div className = { styles . fieldContainer } >
211
239
< div className = { `${ styles . labelContainer } ${ styles . titleContainer } ` } >
0 commit comments