Skip to content

Commit

Permalink
Fixes #29106 - orderable select value
Browse files Browse the repository at this point in the history
(cherry picked from commit 4683162)
  • Loading branch information
ezr-ondrej authored and tbrisker committed Feb 23, 2020
1 parent b5c2d79 commit dbd7b2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -19,6 +19,7 @@ const OrderableSelect = ({
defaultValue,
value,
options,
name,
...props
}) => {
const [internalValue, setInternalValue] = useInternalValue(
Expand All @@ -29,7 +30,7 @@ const OrderableSelect = ({
setInternalValue(orderDragged(internalValue, dragIndex, hoverIndex));
};

// hack the form-control, which in TypeAhead so it will be duplicated
// hack the form-control, which is already in TypeAhead so it would be duplicated
const classesWithoutFormControl =
className &&
className
Expand All @@ -51,6 +52,7 @@ const OrderableSelect = ({
moveDraggedOption={moveDraggedOption}
{...tokenProps}
/>
{name && <input type="hidden" name={name} value={option.value} />}
</div>
)}
{...props}
Expand All @@ -68,6 +70,7 @@ const OrderableSelect = ({
OrderableSelect.propTypes = {
options: PropTypes.arrayOf(PropTypes.object).isRequired,
id: PropTypes.string.isRequired,
name: PropTypes.string,
onChange: PropTypes.func,
defaultValue: PropTypes.array,
value: PropTypes.array,
Expand All @@ -78,6 +81,7 @@ OrderableSelect.defaultProps = {
onChange: noop,
defaultValue: [],
value: null,
name: null,
className: '',
};

Expand Down
Expand Up @@ -63,4 +63,22 @@ describe('OrderableSelect', () => {
expect(selected[1].value).toBe('dnk');
expect(selected[2].value).toBe('no');
});

it('renders inputs if name given', () => {
const value = ['yes', 'no', 'dnk'];
const wrapper = mount(
<WrapedInTestContext
id="testOrderable"
options={yesNoOpts}
value={value}
name="uncertain_select[]"
/>
);
const inputs = wrapper.find('input[type="hidden"]');
expect(inputs).toHaveLength(3);
inputs.forEach((input, idx) => {
expect(input.prop('value')).toBe(value[idx]);
expect(input.prop('name')).toBe('uncertain_select[]');
});
});
});

0 comments on commit dbd7b2d

Please sign in to comment.