Skip to content

SmartComboBox not working on a French computer #48

@Zaraxxx

Description

@Zaraxxx

There is a problem in \smartcomponents\src\SmartComponents.AspNetCore\SmartComboBox\SmartComboBoxEndpointRouteBuilderExtensions.cs:

var form = httpContext.Request.Form;
if (!(form.TryGetValue("inputValue", out var inputValue) && !string.IsNullOrEmpty(inputValue))
    || !(form.TryGetValue("maxResults", out var maxResultsString) && int.TryParse(maxResultsString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var maxResults))
    || !(form.TryGetValue("similarityThreshold", out var similarityThresholdString) && float.TryParse(similarityThresholdString, NumberStyles.Float, CultureInfo.InvariantCulture, out var similarityThreshold)))
{
    return Results.BadRequest("inputValue, maxResults, and similarityThreshold are required");
}

if (maxResults < 1 || maxResults > 100)
{
    return Results.BadRequest("maxResults must be less than or equal to 100");
}

In Line 38, I had to change the code to make it work on my French PC because similarityThresholdString was "0,5" (with a coma) and this fails in the float.TryParse

Here is the fixed code:

var form = httpContext.Request.Form;
if (!(form.TryGetValue("inputValue", out var inputValue) && !string.IsNullOrEmpty(inputValue)))
{
    return Results.BadRequest("inputValue is required");
}
if (!(form.TryGetValue("maxResults", out var maxResultsString) && int.TryParse(maxResultsString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var maxResults)) )
{
    return Results.BadRequest("maxResults is required");
}
if (!(form.TryGetValue("similarityThreshold", out var similarityThresholdString)))
{
    return Results.BadRequest("similarityThreshold is required");
}
var similarityThreshold = float.Parse(similarityThresholdString.ToString().Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture);
if (maxResults < 1 || maxResults > 100)
{
    return Results.BadRequest("maxResults must be less than or equal to 100");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions