-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed search for invalid label and/or value #2179
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,24 +20,35 @@ function filterOptions (options, filterValue, excludeOptions, props) { | |
if (excludeOptions && excludeOptions.indexOf(option[props.valueKey]) > -1) return false; | ||
if (props.filterOption) return props.filterOption.call(this, option, filterValue); | ||
if (!filterValue) return true; | ||
var valueTest = String(option[props.valueKey]); | ||
var labelTest = String(option[props.labelKey]); | ||
|
||
var value = option[props.valueKey]; | ||
var label = option[props.labelKey]; | ||
var hasValue = typeof (value) !== 'undefined' && value !== null && value !== ''; | ||
var hasLabel = typeof (label) !== 'undefined' && label !== null && label !== ''; | ||
|
||
if (!hasValue && !hasLabel) { | ||
return false; | ||
} | ||
|
||
var valueTest = hasValue ? String(value) : null; | ||
var labelTest = hasLabel ? String(label) : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not include this in the hasX checks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because there is situation when only one of label or value is invalid and still need to search in valid field. |
||
|
||
if (props.ignoreAccents) { | ||
if (props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); | ||
if (props.matchProp !== 'value') labelTest = stripDiacritics(labelTest); | ||
if (valueTest && props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); | ||
if (labelTest && props.matchProp !== 'value') labelTest = stripDiacritics(labelTest); | ||
} | ||
|
||
if (props.ignoreCase) { | ||
if (props.matchProp !== 'label') valueTest = valueTest.toLowerCase(); | ||
if (props.matchProp !== 'value') labelTest = labelTest.toLowerCase(); | ||
if (valueTest && props.matchProp !== 'label') valueTest = valueTest.toLowerCase(); | ||
if (labelTest && props.matchProp !== 'value') labelTest = labelTest.toLowerCase(); | ||
} | ||
|
||
return props.matchPos === 'start' ? ( | ||
(props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue) || | ||
(props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue) | ||
(valueTest && props.matchProp !== 'label' && valueTest.substr(0, filterValue.length) === filterValue) || | ||
(labelTest && props.matchProp !== 'value' && labelTest.substr(0, filterValue.length) === filterValue) | ||
) : ( | ||
(props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0) || | ||
(props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0) | ||
(valueTest && props.matchProp !== 'label' && valueTest.indexOf(filterValue) >= 0) || | ||
(labelTest && props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0) | ||
); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract this logic into a function?