We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Close the suggestion list

Hi,

I created an autocomplete with datasource on server side.
if the value does not exist (check in on focus out), i open a modal dialog for create a new value.

if the user write a new value and click (not with tab) on other field, the suggestion list can open but it will not close.
How can we to force by javascript to close the suggestion list?

i try $(this.elementId).ejAutocomplete("close");
but i receive an exception.

Regards,
Mickael

3 Replies

RJ Rekha J Syncfusion Team January 30, 2017 11:12 AM UTC

Hi Mickael,   
  
Thanks for contacting Syncfusion Support.   
  
To achieve your requirement, we have provided a workaround solution. That is, you have to use CSS for suggestionList “display:none” when the suggestionList needs to be closed.    
  
We have created a simple sample to achieve your requirement. In our sample, we have two buttons. One button is used to open the suggestionList. Another button is used to hide the suggestionList. Both actions are done by using click event of the buttons.   
  
You can download the sample from this link:   
  
Regards,   
Rekha  



DA Dan November 30, 2018 03:36 PM UTC

This doesn't appear to work when coming back from an AllowAddNew() call. The suggestion list remains open. I'm using EJ1 with MVC, version 16.3.0.29. Code looks like this Any suggestions on how to get the suggestion list to close up after the item gets added on the server? Thanks.

View
        @{
            Html.EJ().Autocomplete("Specialties")
                .Datasource((IEnumerable<Specialty>) ViewData["Specialties"])
                .AutocompleteFields(f => f.Text("Name").Key("Id"))
                .Width("100%")
                .MultiSelectMode(MultiSelectModeTypes.VisualMode)
                .AllowAddNew(true)
                .Value(Model.Specialties)
                .ClientSideEvents(c => c.Select("onSpecialtySelect"))
                .Readonly(isReadOnly)
                .HtmlAttributes(new Dictionary<string, object> {{"name", "Specialties"}})
                .Render();
        }

Script
    function onSpecialtySelect(args){ 
        if(args.text.indexOf('Add New') >= 0){ 
            var newval = args.text.replace('(Add New)',''); 
            $.ajax({ 
                url: '@Url.Action("AddSpecialty", "Contact")', 
                data: { specialtyName: newval.trim() }, 
                type: 'POST', 
                dataType: "json", 
                success: function (response) { 
                    var ac = $("#Specialties").ejAutocomplete("instance"); 
                    ac.model.dataSource.push({Name:response[0].Name,Id:response[0].Id}); 
                    ac._doneRemaining();
                    ac.suggestionList.css("display", "none");
                } 
            }); 
        } 
    } 

Controller
        [HttpPost]
        public ActionResult AddSpecialty(Specialty model, string specialtyName)
        {
            var dbContext = new MyDbContext();
            var specialty = new Specialty {Name = specialtyName };
            dbContext.Specialties.Add(specialty);
            dbContext.SaveChanges();

            return Json(dbContext.Specialties.ToList());
        }

Model
    public class Specialty {
        public int Id { get; set; }
        public string Name { get; set; }
    }




DL Deepa Loganathan Syncfusion Team December 5, 2018 07:36 AM UTC

Hi Dan,  
 
We regret the delay in reply. 
 
We have analyzed your query and have updated the solution based on the analysis in an incident under your direct-trac account. Please follow up the incident for more details.  
 
  
Please click here to login to your Direct Trac login with the below link.  
 
  
  
 
Regards,  
Deepa L. 


Loader.
Up arrow icon