Selected Item needs to be selected TWICE to actually submit
So issue is similar to this previous thread with no completion/solution: https://www.syncfusion.com/forums/179010/items-selection-is-working-after-selecting-that-item-twice-not-getting-selected-on-first
I have a simple SF Autocomplete item on a page that is bound to a class list of employees. The SF Autocomplete searches by employeeName. The search feature works fine but when trying to select, the item does not register as selected until I do it twice.
- Type in partial name to get list of matches & select employee
- Employee record was selected but did not register in code so AddBtnIsDisabled = true
- Backspace 1 to trigger list and select this employee Again
- Process runs through code again but this time the values are found and AddBtnIsDisabled = false
Control on Page:
<div class="form">
<br />
<SfAutoComplete ID="AddEmpAC" @ref="AddEmpACRef"
Placeholder="Select an Employee"
TValue="string"
TItem="VEmployeeDemo"
DataSource="@empL" AllowFiltering="true"
Width="300px">
<AutoCompleteEvents TValue="string" TItem="VEmployeeDemo" OnValueSelect="AddEmpSelectAction" ></AutoCompleteEvents>
<AutoCompleteFieldSettings Value="EmployeeName" > </AutoCompleteFieldSettings>
</SfAutoComplete>
<SfButton id="SubmitSOBtn" CssClass="submitBtn" OnClick="SubmitSOClick" Disabled="@AddBtnIsDisabled"><i class="e-icons e-plus"> </i> Save </SfButton>
<SfButton id="CancelSOBtn" CssClass="cancelBtn" OnClick="CancelSOClick" Disabled="false"><i class="e-icons e-close"> </i> Cancel </SfButton>
</div>
Code:
protected override void OnInitialized()
{
subOL = substituteService.GetSubstituteOverwriteL(); //Get list of current SO records
empL = empService.GetVEmployeeDemoL(); // TODO: Filter list of employees that are NOT IN SO tbl already
}
public void AddEmpSelectAction()
{
//Capture selection from SFAutocomplet control AddEmpAC into VEmployee container AutoCompleteObj
this.AutoCompleteObj = this.AddEmpACRef.GetDataByValue(this.AddEmpACRef.Value);
//If Value Selected, enable button
AddBtnIsDisabled = (this.AutoCompleteObj == null) ? true : checkSOExists(this.AutoCompleteObj.EmployeeID); //false;
}
public bool checkSOExists(string eid)
{
bool exists = false;
exists = subOL.Exists(so => so.EmployeeID == eid);
return exists;
}
public void AddEmpValueChangeAction()
{
this.AutoCompleteObj = this.AddEmpACRef.GetDataByValue(this.AddEmpACRef.Value);
if (this.AutoCompleteObj != null)
{
if (!checkSOExists(this.AutoCompleteObj.EmployeeID))
{
string orgData = String.IsNullOrEmpty(orgService.GetSingleOrganizationByID(this.AutoCompleteObj.CAMPUS).FullCampusName) ? this.AutoCompleteObj.CAMPUS + " - Org No longer Valid" : orgService.GetSingleOrganizationByID(this.AutoCompleteObj.CAMPUS).FullCampusName;
previewEmpTitle = this.AutoCompleteObj.PositionFullDescription == null ? "" : this.AutoCompleteObj.PositionFullDescription;
previewEmpCampus = orgData;
hideEmpTB = false;
AddBtnIsDisabled = false;
}
else
{
this.ToastService.ShowToast("Information", "Unable to locate record for: " + this.AutoCompleteObj.EmployeeID);
hideEmpTB = true;
AddBtnIsDisabled = true;
}
}
else
{
AddBtnIsDisabled = true;
hideEmpTB = true;
}
}
Hi Margaret Villesca,
Thank you for reaching out to us with your concern regarding the SFAutocomplete component.
After a thorough review of your query, we have prepared a code snippet that should resolve the issue you are experiencing. In the updated code snippet, we have made modifications to use the select event args to bind the item data to the autocomplete object instead of relying on the "GetDataByValue" method.
public void AddEmpSelectAction(SelectEventArgs<Employee> args) { this.AutoCompleteObj = args.ItemData; AddBtnIsDisabled = (this.AutoCompleteObj == null) ? true : checkSOExists(this.AutoCompleteObj.ID); //false; } |
With these changes, the selected item should be registered correctly, and you should no longer encounter the need to select it twice.
I found the issue shortly after posting this item. With this new incident layout, I am not sure how to Close/Cancel this request.
Hi Margaret,
Glad to know your issue has been resolved. We will mark this forum as solved. Please get back to us for assistance in the future.
Regards,
Shereen
- 3 Replies
- 3 Participants
-
MV Margaret Villesca
- Aug 3, 2023 04:49 PM UTC
- Aug 8, 2023 06:34 AM UTC