Skip to content

Commit

Permalink
FIX (add new): disallow to add value with same valiuField
Browse files Browse the repository at this point in the history
  • Loading branch information
sanusart committed Feb 28, 2019
1 parent cd579c5 commit ae454c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ const Dropdown = ({ props, state, methods }) => (
props.dropdownRenderer({ props, state, methods })
) : (
<React.Fragment>
{props.create && state.search && !valueExistInSelected(state.search, state.values) && (
<AddNew color={props.color} onClick={() => methods.createNew(state.search)}>
{props.create && state.search && !valueExistInSelected(state.search, state.values, props) && (
<AddNew
className="react-dropdown-select-dropdown-add-new"
color={props.color}
onClick={() => methods.createNew(state.search)}>
{props.createNewLabel.replace('{search}', `"${state.search}"`)}
</AddNew>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const valueExistInSelected = (value, values) => !!values.find((val) => val.value === value);
export const valueExistInSelected = (value, values, props) =>
!!values.find((val) => val[props['valueField']] === value);

export const hexToRGBA = (hex, alpha) => {
const RR = parseInt(hex.slice(1, 3), 16);
Expand Down

0 comments on commit ae454c4

Please sign in to comment.