Skip to content

Child-Binding don't work #9612

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
UrielMhezzek opened this issue Apr 21, 2019 · 5 comments
Closed

Child-Binding don't work #9612

UrielMhezzek opened this issue Apr 21, 2019 · 5 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@UrielMhezzek
Copy link

I want to make a inputlayout for all my paramters on my hero-object. i start with the name of the instance of my hero-object.

In first Line the normal Inputfield. It works, in second line, the Inputfield-Component, that don't work.

        <input type="text" bind-value-oninput="@hero.Name" />
        <InputField Label="Name" bind-Value="@hero.Name"></InputField>

inputfield.csthml

<div class="form-group @(Orientation == InputFieldOrientation.Horizontal ? "row" : "")">
    <label class="col-sm-2 col-form-label">@Label</label>
    <div class="col-sm-10 @(Orientation == InputFieldOrientation.Horizontal ? "text-center" : "")">
        <input class="form-control form-control-dark w-100" type="text" placeholder="@Label" bind-value-oninput="@Value" />    </div>
</div>

@functions {
    [Parameter] private string Label { get; set; }
    [Parameter] private string Value { get; set; }
    [Parameter] private Action<string> ValueChanged { get; set; }
    [Parameter] private InputFieldOrientation Orientation { get; set; } = InputFieldOrientation.Horizontal;
}
@blowdart blowdart added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 21, 2019
@medeirosraul
Copy link

medeirosraul commented Apr 21, 2019

I had same question some days ago.
The answer is in here #8386

@danroth27 danroth27 added the area-blazor Includes: Blazor, Razor Components label Apr 22, 2019
@danroth27
Copy link
Member

@UrielMhezzek Could you please clarify what exactly isn't working? What is the expected behavior and what behavior are you seeing?

@SteveSandersonMS
Copy link
Member

In the code posted, nothing invokes ValueChanged, so it will never apply any updates to the bound value.

For an example of how to do this as intended, please see the answer that @medeirosraul linked to: #8386 (comment)

@UrielMhezzek
Copy link
Author

@danroth27 Forgive me if I don't find the right words. My English is modest.

I have a Hero object. But it can be any other object. I would like to build an element that interprets all my definitions and outputs them in a standard way.

What I have already achieved is that I create Hero objects via my page and have a form there in which I assign an input field to each of the corresponding properties. Let's start with Name. Name is a string. So the input field is selected as input. With Gender, which is a list, the properties create a list accordingly. This already works. The corresponding default values are also displayed in the input fields. A property of the hero object is not a classic basic type but a small object with further information that is relevant for the input field (e.g. which list elements are possible, whether it is a string, integer or a complex object, etc.).

What doesn't happen is that I create a two-way-binding, so when I make a change to the name, the change is written back to the hero object.

So I just want to say my input field
<InputField Value="@hero.Name" />
And then a Redering shall take place, which resembles that.
<input type="text" bind-value-oninput="@hero.Name.Value" />

This means that the Hero element should also be changed each time the button is pressed. I hope this is more understandable now.

I have noticed in my property object that Value is changed from Name. But other elements that use Name.Value don't get any information about it.
A test with Set Manuals (via a button) showed me that the value seems to have arrived in the Hero object.

@UrielMhezzek
Copy link
Author

i have found a solution. But i don't understand, why twowaybinding is not possible here.

<input value="@Value.Value" oninput="@((e) => ValueChanged.InvokeAsync((string)e.Value))">
[Parameter] EventCallback<string> ValueChanged { get; set; }

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

6 participants