-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Support chained 'bind' on components #5504
Comments
I believe you need to call the <div>
<input value="@myValue" onchange="@InputChanged" />
</div>
@functions
{
public string myValue { get; set; }
public Action<string> myValueChanged { get; set; }
void InputChanged(UIChangeEventArgs e)
{
myValue = (string)e.Value;
myValueChanged(myValue);
Console.WriteLine($"InputChanged: {myValue}");
}
} However, the <input bind="@Test" /><br />
<myInput myValue="@Test" myValueChanged="@MyValueChanged" /><br />
test: @Test
@functions {
public string Test { get; set; }
void MyValueChanged(string myValue)
{
Console.WriteLine($"MyValueChanged: {myValue}");
Test = myValue;
StateHasChanged();
}
} |
Ah, this helps. I now see that the documentation nowhere mentions that databinding is two-way. I assumed it was going to work this way, I guess because Aurelia and Angular do it this way. Are you planning on making it work this way? I'll opt for that, it looks cumbersome as it is right now. |
@rynowak To make the multiple-connected-bindings scenario work correctly, I propose we amend the codegen output for
What do you think? Is the second item there technically reasonable to implement - do we know whether a certain-named other property exists at the right point in the compilation process? I'm guessing that the two-phase compile makes this possible, though I don't know whether it would be convenient to do still. @floreseken Data binding is two way, so I'm not sure what you mean by that comment. There are a couple of usability issues with it, for which I'm proposing the two fixes above. |
@SteveSandersonMS - yes, both of these sounds like good enhancements and very doable.
FYI If you're in the case where you don't declare MyPropChanged we don't provide automatic completion for |
@rynowak Sounds right! |
If I have something like bind-myProp-myPropChanged="somevariable" and not actually declare myPropChanged will it be invoked? |
No, even if you do declare it, it doesn't get invoked magically. But Steve is proposing a change that will. |
@SteveSandersonMS could this please be part of the 0.4 release? It is holding me back from creating any component with inputs in them. |
I've written a blogpost on a workaround which involves less code if you have a lot of components. http://flores.eken.nl/blazor-custom-component-with-2-way-databinding/ |
Maybe something for 0.6.0? which could potentially speed up the development of component libs. |
I'd just run into this bug trying to create bootstrap form components. It looks like anything in a RenderFragment doesn't seem to work, even with My test repo: https://github.com/conficient/BlazorBug01 There are two different problems here: first, a Suggestions welcome. |
@danroth27 could I make a request to include this issue in 0.7.0, or failing that the next release? It appears this problem exists in server-side as well so would affect Razor Components going forward. Plus it will make creating re-usable components much easier (e.g. Bootstrap 4 layouts as in my repo are a classic example) |
@conficient I'll optimistically put this in the milestone and we'll see if we can get to it. |
I created a fiddle that shows I believe the same issue: https://blazorfiddle.com/s/861k07nk If you change the value in the calendar, the value is updated in the component, but not in the parent. I hope this helps. |
We expect to handle this as part of #6351 |
I must be doing something wrong.
Made this component:
And use this in a page like this:
Now I expect that typing in either input on this page would result in the same values in both inputs. But this seems to work only one-way: from the input to the control and not the other way around.
This is supposed to work right? What am I doing wrong?
Note (from @SteveSandersonMS)
I expect fixing this will also fix #1490. Any proposed fix for this issue should also be checked to verify it accounts for the scenarios raised at #1490, and if it doesn't we'll reopen #1490 as a separate issue.
The text was updated successfully, but these errors were encountered: