Allow separate keys for text and HTML views of the element
parent
61ae0aea15
commit
a3d1438243
|
@ -1,5 +1,5 @@
|
|||
// Simple Dropdown/Autocomplete with single/multiple selection and easy customisation via CSS modules
|
||||
// Version 2020-04-27
|
||||
// Version 2021-08-25
|
||||
// License: LGPLv3.0+
|
||||
// (c) Vitaliy Filippov 2019+
|
||||
|
||||
|
@ -28,6 +28,8 @@ export default class Selectbox extends React.PureComponent
|
|||
keepFocusOnChange: PropTypes.bool,
|
||||
// item name key - default "name"
|
||||
labelKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
// item text key - default "name"
|
||||
textKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
// item id key - default "id"
|
||||
valueKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
// automatically filter autocomplete options based on user input if `true`
|
||||
|
@ -243,7 +245,7 @@ export default class Selectbox extends React.PureComponent
|
|||
else if (this.props.source instanceof Array)
|
||||
{
|
||||
this.items = this.props.source;
|
||||
this.item_hash = this.items.reduce((a, c) => { a[c[this.props.valueKey||'id']] = c[this.props.labelKey||'name']; return a; }, {});
|
||||
this.item_hash = this.items.reduce((a, c) => { a[c[this.props.valueKey||'id']] = c[this.props.textKey||'name']; return a; }, {});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -261,7 +263,7 @@ export default class Selectbox extends React.PureComponent
|
|||
}
|
||||
else
|
||||
{
|
||||
const n = this.props.labelKey||'name';
|
||||
const n = this.props.textKey||'name';
|
||||
const q = this.state.query.toLowerCase();
|
||||
this.filtered_items = this.items.filter(e => e[n].toLowerCase().indexOf(q) >= 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue