@rjsf/react-bootstrap 6.4.2 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/react-bootstrap",
3
- "version": "6.4.2",
3
+ "version": "6.5.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -61,8 +61,8 @@
61
61
  ]
62
62
  },
63
63
  "peerDependencies": {
64
- "@rjsf/core": "^6.4.x",
65
- "@rjsf/utils": "^6.4.x",
64
+ "@rjsf/core": "^6.5.x",
65
+ "@rjsf/utils": "^6.5.x",
66
66
  "react": ">=18",
67
67
  "react-bootstrap": "^2.x"
68
68
  },
@@ -71,10 +71,10 @@
71
71
  "node": ">=20"
72
72
  },
73
73
  "devDependencies": {
74
- "@rjsf/core": "6.4.2",
75
- "@rjsf/snapshot-tests": "6.4.2",
76
- "@rjsf/utils": "6.4.2",
77
- "@rjsf/validator-ajv8": "6.4.2",
74
+ "@rjsf/core": "6.5.1",
75
+ "@rjsf/snapshot-tests": "6.5.1",
76
+ "@rjsf/utils": "6.5.1",
77
+ "@rjsf/validator-ajv8": "6.5.1",
78
78
  "eslint": "^8.57.1",
79
79
  "react-bootstrap": "^2.10.10"
80
80
  },
@@ -2,10 +2,11 @@ import { ChangeEvent, FocusEvent } from 'react';
2
2
  import Form from 'react-bootstrap/Form';
3
3
  import {
4
4
  ariaDescribedByIds,
5
+ enumOptionValueDecoder,
5
6
  enumOptionsDeselectValue,
6
7
  enumOptionsIsSelected,
7
8
  enumOptionsSelectValue,
8
- enumOptionsValueForIndex,
9
+ getOptionValueFormat,
9
10
  optionId,
10
11
  FormContextType,
11
12
  RJSFSchema,
@@ -31,6 +32,7 @@ export default function CheckboxesWidget<
31
32
  onFocus,
32
33
  }: WidgetProps<T, S, F>) {
33
34
  const { enumOptions, enumDisabled, inline, emptyValue } = options;
35
+ const optionValueFormat = getOptionValueFormat(options);
34
36
  const checkboxesValues = Array.isArray(value) ? value : [value];
35
37
 
36
38
  const _onChange =
@@ -44,9 +46,9 @@ export default function CheckboxesWidget<
44
46
  };
45
47
 
46
48
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
47
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
49
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
48
50
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
49
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
51
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
50
52
 
51
53
  return (
52
54
  <Form.Group>
@@ -2,8 +2,10 @@ import { ChangeEvent, FocusEvent } from 'react';
2
2
  import Form from 'react-bootstrap/Form';
3
3
  import {
4
4
  ariaDescribedByIds,
5
+ enumOptionValueDecoder,
6
+ enumOptionValueEncoder,
5
7
  enumOptionsIsSelected,
6
- enumOptionsValueForIndex,
8
+ getOptionValueFormat,
7
9
  optionId,
8
10
  FormContextType,
9
11
  RJSFSchema,
@@ -24,13 +26,14 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
24
26
  onFocus,
25
27
  }: WidgetProps<T, S, F>) {
26
28
  const { enumOptions, enumDisabled, emptyValue } = options;
29
+ const optionValueFormat = getOptionValueFormat(options);
27
30
 
28
31
  const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
29
- onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
32
+ onChange(enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
30
33
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
31
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
34
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
32
35
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
33
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
36
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
34
37
 
35
38
  const inline = Boolean(options && options.inline);
36
39
 
@@ -52,7 +55,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
52
55
  disabled={disabled || itemDisabled || readonly}
53
56
  checked={checked}
54
57
  required={required}
55
- value={String(index)}
58
+ value={enumOptionValueEncoder(option.value, index, optionValueFormat)}
56
59
  onChange={_onChange}
57
60
  onBlur={_onBlur}
58
61
  onFocus={_onFocus}
@@ -2,9 +2,11 @@ import { ChangeEvent, FocusEvent } from 'react';
2
2
  import FormSelect from 'react-bootstrap/FormSelect';
3
3
  import {
4
4
  ariaDescribedByIds,
5
+ enumOptionSelectedValue,
6
+ enumOptionValueDecoder,
7
+ enumOptionValueEncoder,
8
+ getOptionValueFormat,
5
9
  FormContextType,
6
- enumOptionsIndexForValue,
7
- enumOptionsValueForIndex,
8
10
  RJSFSchema,
9
11
  StrictRJSFSchema,
10
12
  WidgetProps,
@@ -34,6 +36,7 @@ export default function SelectWidget<
34
36
  const { enumOptions, enumDisabled, emptyValue: optEmptyValue } = options;
35
37
 
36
38
  const emptyValue = multiple ? [] : '';
39
+ const optionValueFormat = getOptionValueFormat(options);
37
40
 
38
41
  function getValue(event: FocusEvent | ChangeEvent | any, multiple?: boolean) {
39
42
  if (multiple) {
@@ -45,14 +48,14 @@ export default function SelectWidget<
45
48
  return event.target.value;
46
49
  }
47
50
  }
48
- const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
51
+ const selectValue = enumOptionSelectedValue<S>(value, enumOptions, !!multiple, optionValueFormat, emptyValue);
49
52
  const showPlaceholderOption = !multiple && schema.default === undefined;
50
53
 
51
54
  return (
52
55
  <FormSelect
53
56
  id={id}
54
57
  name={htmlName || id}
55
- value={typeof selectedIndexes === 'undefined' ? emptyValue : selectedIndexes}
58
+ value={selectValue}
56
59
  required={required}
57
60
  multiple={multiple}
58
61
  disabled={disabled || readonly}
@@ -62,19 +65,19 @@ export default function SelectWidget<
62
65
  onBlur &&
63
66
  ((event: FocusEvent) => {
64
67
  const newValue = getValue(event, multiple);
65
- onBlur(id, enumOptionsValueForIndex<S>(newValue, enumOptions, optEmptyValue));
68
+ onBlur(id, enumOptionValueDecoder<S>(newValue, enumOptions, optionValueFormat, optEmptyValue));
66
69
  })
67
70
  }
68
71
  onFocus={
69
72
  onFocus &&
70
73
  ((event: FocusEvent) => {
71
74
  const newValue = getValue(event, multiple);
72
- onFocus(id, enumOptionsValueForIndex<S>(newValue, enumOptions, optEmptyValue));
75
+ onFocus(id, enumOptionValueDecoder<S>(newValue, enumOptions, optionValueFormat, optEmptyValue));
73
76
  })
74
77
  }
75
78
  onChange={(event: ChangeEvent) => {
76
79
  const newValue = getValue(event, multiple);
77
- onChange(enumOptionsValueForIndex<S>(newValue, enumOptions, optEmptyValue));
80
+ onChange(enumOptionValueDecoder<S>(newValue, enumOptions, optionValueFormat, optEmptyValue));
78
81
  }}
79
82
  aria-describedby={ariaDescribedByIds(id)}
80
83
  >
@@ -82,7 +85,7 @@ export default function SelectWidget<
82
85
  {(enumOptions as any).map(({ value, label }: any, i: number) => {
83
86
  const disabled: any = Array.isArray(enumDisabled) && (enumDisabled as any).indexOf(value) != -1;
84
87
  return (
85
- <option key={i} id={label} value={String(i)} disabled={disabled}>
88
+ <option key={i} id={label} value={enumOptionValueEncoder(value, i, optionValueFormat)} disabled={disabled}>
86
89
  {label}
87
90
  </option>
88
91
  );
@@ -59,6 +59,7 @@ export default function WrapIfAdditionalTemplate<
59
59
  <Form.Group>
60
60
  {displayLabel && <Form.Label htmlFor={keyId}>{keyLabel}</Form.Label>}
61
61
  <Form.Control
62
+ key={label}
62
63
  required={required}
63
64
  defaultValue={label}
64
65
  disabled={disabled || readonly}