2

I am using magicSuggest with server-side filtering for some of my input fields. In a form, I want to use it with Google API Places in order to get the postal code for places. The thing is that I want the user to insert only numeric values to my input for the search.

From the documentation I am guessing that the configuration options that should be related to what I want to do are:

vregex regulates the type of entries set.

vtype requires an entry to match a given type.

I have tried the following settings:

vtype: "int", vtype: "number"
vregex: /^\d+$/, vregex: "/^\d+$/"

and none of them hasn't triggered any sort of error, not allowance or indication that the field doesn't accept string values. Moreover whatever I write the input triggers the server side filtering and gives me results as expected to a string input.

My complete illustration is:

HTML

<input asp-for="ZipCode" id="zipCode" class="form-control" placeholder=""  />

Javascript

$('#zipCode').magicSuggest({
        allowFreeEntries: false,
        maxSelection: 1,
        minChars: 3,
        useTabKey: true,
        mode: 'remote',
        valueField: 'id',
        displayField: 'description',
        autoSelect: true,
        vregex: reg,
        renderer: function (region) {
            return '<div>' +
                '<div style="font-family: Arial; font-weight: bold">' + region.structured_formatting.main_text + '</div>' +
                '<div>' + region.description + '</div>' +
                '</div>';
        },
        data: params.searchRegionsUrl
    });

Controller

    public async Task<JsonResult> GetRegions(string query)
    {
        List<GoogleApiPlace> places = new List<GoogleApiPlace>();
        try
        {
            places = await GoogleApisPlacesManagement.GetRegions(query);

        }
        catch (Exception ex)
        {
            // Log exception
        }
        return Json(places.OrderBy(o => o.description));
    }
Community
  • 1
  • 1
Anastasios Selmani
  • 3,579
  • 3
  • 32
  • 48

0 Answers0