-
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
Nested binding using @bind-xxx syntax does not work #11679
Comments
Thanks for contacting us, @conficient .
Alternatively, you can simply subclass from the |
I tried the approach you suggested but this results in a WASM error:
I think this is because the ValueChanged event handler isn't set? I will push the updated version on this code to my repo. This issue can remain closed though. |
If your goal is to wrap up an If you're really determined to compose, then accept an |
Thanks @rynowak - yes I wanted to get rid of boilerplate |
I started to see the following error after upgrading from preview5 to preview6
this is my custom component @inherits CcInputTextComponent
@using Microsoft.AspNetCore.Components
<input type="@Type"
class="@CssClass"
id="@Id"
value="@BindMethods.GetValue(CurrentValue)"
onchange="@BindMethods.SetValueHandler(__value => CurrentValue = __value, CurrentValue)"
placeholder="@PlaceHolder"
/>
the "code behind" - I prefer not to use the @ code{} I like the idea of having the csharp completely separated from the razor using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.RenderTree;
namespace BzTest.Shared.CcInputText
{
public class CcInputTextComponent: InputText
{
[Parameter] public string Type { get; set; } = "text";
[Parameter] public string PlaceHolder { get; set; }
}
} the use of the component <CcInputText id="Password" Type="password" bind-Value="@loginRequest.Password" Class="form-control input_pass" PlaceHolder="Password"></CcInputText> |
use @bind-Value instead of bind-Value. See the preview6 upgrade notes for more details |
For those that end up here like me, it appears as though "@bind-Value" became case sensitive at some point. |
Yes it did. Which now allows us to create components like which don't interfere with the html tag (YAY!) |
Describe the bug
Binding values using
@bind-XXX
binding syntax does not work if nested.Demo
To Reproduce
Steps to reproduce the behavior:
@bind-Value
syntax in theShared
folderEditForm
in theIndex.razor
page and a model to bind toInputText
component, bind using@bind-Value
to one model property@bind-Value
Expected behavior
Expected the binding to work with nested controls, so both properties of the model are updated when the input control is changed.
Actual behavior
A direct binding with
InputText
works but the custom control binding does not bind to the model. It binds when initially created but updates to the control do not get passed back the to page model.Sample code
Example repo created at https://github.com/conficient/BlazorBug04
MyControl.razor
Index.razor
Additional context
Previously reported on Blazor repo: #1490
Also reported in aspnetcore repo: #5504
Related: #6351 was supposed to fix?
Include the output of
dotnet --info
The text was updated successfully, but these errors were encountered: