Skip to content

Commit

Permalink
Fixed issues based on the search and added functionality to listen to…
Browse files Browse the repository at this point in the history
… the OnKeyUp(enter) event
  • Loading branch information
Victor Sanchez authored and Victor Sanchez committed Nov 15, 2020
1 parent e72bdaa commit 0eacd91
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions MultiselectRecordsEntity/MultiselectRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const MultiselectRecords = (props: IMultiselectProps) => {
const getRecordsFromTextField = async () => {
let filter = `$filter=`;
const fieldValueArray = getTextFieldJSON();
if(fieldValueArray.length == 0) {
return null;
}
for(let fieldValue of fieldValueArray) {
if(fieldValue != null) {
filter += `${props.attributeid} eq ${JSON.parse(fieldValue)["id"]} or `
Expand All @@ -66,12 +69,12 @@ const getRecordsFromTextField = async () => {
return recordsRetrieved;
}

const setSelectedItemsWhenOpened = async(recordsPassedParam: any) => {
const setSelectedItemsWhenOpened = async(recordsPassedParam: any = null) => {
const recordsRetrieved: any = await getRecordsFromTextField();
const recordsPassedParamCopy = recordsPassedParam.slice();

if(recordsRetrieved.entities.length != 0 ) {
const selectedItemsWhenOpened: any = recordsRetrieved.entities;
if(recordsPassedParamCopy != null || recordsRetrieved != null && recordsRetrieved.entities.length != 0 ) {
const selectedItemsWhenOpened: any = recordsRetrieved != null ? recordsRetrieved.entities : [];
for (var item of selectedItemsWhenOpened) {
var itemFiltered = recordsPassedParamCopy.filter((x: any) => x[props.attributeid] == item[props.attributeid]);
var index = recordsPassedParamCopy.findIndex((x: any) => x[props.attributeid] == item[props.attributeid]);
Expand Down Expand Up @@ -226,6 +229,7 @@ const getRecordsFromTextField = async () => {
disabled={props.isControlDisabled}
placeholder="Search..."
errorMessage={errorMessage}
onKeyUp={enterFilterRecords}
/>
<PrimaryButton
iconProps={searchIcon}
Expand Down Expand Up @@ -374,7 +378,7 @@ const getRecordsFromTextField = async () => {
/**
* Main trigger when the searchbox is changed
*/
const filterRecords = async (): Promise<any> => {
const filterRecords = (): void => {
//Set the value of our textfield to the input
clearTimeout(timeout);
timeout = setTimeout(async () => {
Expand Down Expand Up @@ -418,6 +422,12 @@ const getRecordsFromTextField = async () => {
setIsError(numberOfError);
}
}

const enterFilterRecords = (event: any): void => {
if(event.key === 'Enter'){
filterRecords();
}
}

/**
* Event when the select elements is clicked
Expand Down

0 comments on commit 0eacd91

Please sign in to comment.