Skip to content

Add method to indicate an event handler should enforce value consistency #17281

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

Closed
SteveSandersonMS opened this issue Nov 21, 2019 · 8 comments
Closed
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) severity-blocking This label is used by an internal tool

Comments

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Nov 21, 2019

In other words, a way to tell Blazor that a given event handler is part of a two-way binding even if you're not using @bind.

It would probably look like this:

<input value="@MyValue" @onchange="MyHandler" @onchange:enforceConsistency />

... or maybe @onchange:sync or @onchange:twoWay. The implementation is simply to emit a builder.SetUpdatesAttributeName call for whatever is the "value" attribute for this element type (e.g., on <input type=checkbox> it would call builder.SetUpdatesAttributeName("checked");).

For more details about the scenario and justification for this design, see #17099 (comment)

@SteveSandersonMS SteveSandersonMS added the area-blazor Includes: Blazor, Razor Components label Nov 21, 2019
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Nov 21, 2019
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0-preview1 milestone Nov 21, 2019
@JvanderStad
Copy link

JvanderStad commented Feb 18, 2020

The @onchange event handler receives a Microsoft.AspNetCore.Components.ChangeEventArgs instance.

namespace Microsoft.AspNetCore.Components
{
    //
    // Summary:
    //     Supplies information about an change event that is being raised.
    public class ChangeEventArgs : EventArgs
    {
        public ChangeEventArgs();

        //
        // Summary:
        //     Gets or sets the new value.
        public object Value { get; set; }
    }
}

Can't we use the Value-setter to reflect changes?

public void ChangeEvent(ChangeEventArgs args)
{
	args.Value = "new value";
}

@hultqvist
Copy link

Could you also look into a scenario where the value is modified elsewhere, for example in a form submit method. The change in MyValue won't be related to the @onchange event.

@hultqvist
Copy link

I'm looking for a workaround.
This one appears to work though there's some magic in there.

async Task MyHandler(ChangeEventArgs args)
{
    var old = Text;
    Text = args.Value as string;
    await Task.Delay(1); //Magic!
    Text = old;

@thalaeg
Copy link

thalaeg commented Jun 2, 2020

@hultqvist I know its a little late, but you can do a get and set with a private variable like this illustrates
https://stackoverflow.com/questions/60378477/filter-blazor-input-field

@javiercn javiercn added affected-medium This issue impacts approximately half of our customers severity-blocking This label is used by an internal tool labels Oct 9, 2020 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Oct 9, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@javiercn javiercn added the feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) label Apr 19, 2021
@JvanderStad
Copy link

Looking forward to this one!

@danroth27
Copy link
Member

@SteveSandersonMS Do we still need this now that we have get/set/after?

@javiercn
Copy link
Member

@SteveSandersonMS I believe this is handled, if not, feel free to reopen

@ghost ghost locked as resolved and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) severity-blocking This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

7 participants