Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using ValueChanged and Value with RangeInput #932

Open
pedroveiga99 opened this issue Nov 5, 2024 · 0 comments
Open

Error when using ValueChanged and Value with RangeInput #932

pedroveiga99 opened this issue Nov 5, 2024 · 0 comments

Comments

@pedroveiga99
Copy link

I had a component with RangeInput component and with Value and ValueChanged

<RangeInput TValue="int" Min="0" Max="100" Step="5" ValueChanged="OnValueChange" Value="brightness" />

@code{
    private int brightness = 50;

    protected override async Task OnInitializedAsync()
    {
        brightness = await screenBrightnessManager.GetCurrentScreenBrightness() ?? brightness;
        isInitialized = true;
    }

    private async Task OnValueChange(int value)
    {
        if (!isInitialized)
            return;

        // Handle it returns a exception
        await screenBrightnessManager.SetScreenBrightness(value);
        brightness = value;
    }
}

And it was giving me an error every time the component was rendered.

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Value cannot be null. (Parameter 'accessor')
System.ArgumentNullException: Value cannot be null. (Parameter 'accessor')
   at System.ArgumentNullException.Throw(String paramName)
   at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
   at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create[Int32](Expression`1 accessor)
   at BlazorBootstrap.RangeInput`1.<OnInitializedAsync>d__5[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

I solved it by using the bind-value set and get. But it should be working the first way.

<RangeInput TValue="int" Min="0" Max="100" Step="5" @bind-Value:get=brightness @bind-Value:set=OnValueChange />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant