Clear button triggers a controller call with empty text

2 posts, 0 answers
  1. François
    François avatar
    5 posts
    Member since:
    Sep 2017

    Posted 18 Sep Link to this post

    I set MinLength on Autocomplete.

    However when I click on the "clear" icon of the autocmplete box there are a few unexpected behaviors

    - there is a call to the controller with empty text

    - the dropdown remains open saying "no data found"

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1263 posts

    Posted 21 Sep Link to this post

    Hello François,

    In our demos when the input is cleared a request is sent to the server and it returns all the items. The No data found message is not displayed:
    Here's the Action that is called:
    public JsonResult GetProducts(string text)
    {
        var northwind = new SampleEntities();
     
     
        var products = northwind.Products.Select(product => new ProductViewModel
        {
            ProductID = product.ProductID,
            ProductName = product.ProductName,
            UnitPrice = product.UnitPrice ?? 0,
            UnitsInStock = product.UnitsInStock ?? 0,
            UnitsOnOrder = product.UnitsOnOrder ?? 0,
            Discontinued = product.Discontinued
        });
     
        if (!string.IsNullOrEmpty(text))
        {
            products = products.Where(p => p.ProductName.Contains(text));
        }
     
        return Json(products, JsonRequestBehavior.AllowGet);
    }

    Could you share your AutoComplete declaration? This would give us a better idea of how it is configured. 

    Regards,
    Ivan Danchev
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top