|
9 | 9 | FieldProps,
|
10 | 10 | FormContextType,
|
11 | 11 | getDiscriminatorFieldFromSchema,
|
| 12 | + getTemplate, |
12 | 13 | getUiOptions,
|
13 | 14 | getWidget,
|
14 | 15 | mergeSchemas,
|
@@ -157,6 +158,12 @@ class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
157 | 158 |
|
158 | 159 | const { widgets, fields, translateString, globalUiOptions, schemaUtils } = registry;
|
159 | 160 | const { SchemaField: _SchemaField } = fields;
|
| 161 | + const MultiSchemaFieldTemplate = getTemplate<'MultiSchemaFieldTemplate', T, S, F>( |
| 162 | + 'MultiSchemaFieldTemplate', |
| 163 | + registry, |
| 164 | + globalUiOptions, |
| 165 | + ); |
| 166 | + |
160 | 167 | const { selectedOption, retrievedOptions } = this.state;
|
161 | 168 | const {
|
162 | 169 | widget = 'select',
|
@@ -215,36 +222,45 @@ class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
215 | 222 | };
|
216 | 223 | });
|
217 | 224 |
|
| 225 | + const selector = ( |
| 226 | + <Widget |
| 227 | + id={this.getFieldId()} |
| 228 | + name={`${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`} |
| 229 | + schema={{ type: 'number', default: 0 } as S} |
| 230 | + onChange={this.onOptionChange} |
| 231 | + onBlur={onBlur} |
| 232 | + onFocus={onFocus} |
| 233 | + disabled={disabled || isEmpty(enumOptions)} |
| 234 | + multiple={false} |
| 235 | + rawErrors={rawErrors} |
| 236 | + errorSchema={fieldErrorSchema} |
| 237 | + value={selectedOption >= 0 ? selectedOption : undefined} |
| 238 | + options={{ enumOptions, ...uiOptions }} |
| 239 | + registry={registry} |
| 240 | + formContext={formContext} |
| 241 | + placeholder={placeholder} |
| 242 | + autocomplete={autocomplete} |
| 243 | + autofocus={autofocus} |
| 244 | + label={title ?? name} |
| 245 | + hideLabel={!displayLabel} |
| 246 | + readonly={readonly} |
| 247 | + /> |
| 248 | + ); |
| 249 | + |
| 250 | + const optionsSchemaField = |
| 251 | + (optionSchema && optionSchema.type !== 'null' && ( |
| 252 | + <_SchemaField {...this.props} schema={optionSchema} uiSchema={optionUiSchema} /> |
| 253 | + )) || |
| 254 | + null; |
| 255 | + |
218 | 256 | return (
|
219 |
| - <div className='panel panel-default panel-body'> |
220 |
| - <div className='form-group'> |
221 |
| - <Widget |
222 |
| - id={this.getFieldId()} |
223 |
| - name={`${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`} |
224 |
| - schema={{ type: 'number', default: 0 } as S} |
225 |
| - onChange={this.onOptionChange} |
226 |
| - onBlur={onBlur} |
227 |
| - onFocus={onFocus} |
228 |
| - disabled={disabled || isEmpty(enumOptions)} |
229 |
| - multiple={false} |
230 |
| - rawErrors={rawErrors} |
231 |
| - errorSchema={fieldErrorSchema} |
232 |
| - value={selectedOption >= 0 ? selectedOption : undefined} |
233 |
| - options={{ enumOptions, ...uiOptions }} |
234 |
| - registry={registry} |
235 |
| - formContext={formContext} |
236 |
| - placeholder={placeholder} |
237 |
| - autocomplete={autocomplete} |
238 |
| - autofocus={autofocus} |
239 |
| - label={title ?? name} |
240 |
| - hideLabel={!displayLabel} |
241 |
| - readonly={readonly} |
242 |
| - /> |
243 |
| - </div> |
244 |
| - {optionSchema && optionSchema.type !== 'null' && ( |
245 |
| - <_SchemaField {...this.props} schema={optionSchema} uiSchema={optionUiSchema} /> |
246 |
| - )} |
247 |
| - </div> |
| 257 | + <MultiSchemaFieldTemplate |
| 258 | + schema={schema} |
| 259 | + registry={registry} |
| 260 | + uiSchema={uiSchema} |
| 261 | + selector={selector} |
| 262 | + optionSchemaField={optionsSchemaField} |
| 263 | + /> |
248 | 264 | );
|
249 | 265 | }
|
250 | 266 | }
|
|
0 commit comments