Skip to content

Calculated field from another field #2833

Answered by stsrki
yangetze asked this question in Q&A
Discussion options

You must be logged in to vote

Try this:

<NumericEdit TValue="decimal" Value="@Field1" ValueChanged="@OnField1Changed" />

<NumericEdit TValue="decimal" Value="@Field2" ReadOnly="true" />

@code{
    decimal Field1;

    decimal Field2;

    Task OnField1Changed( decimal newValue )
    {
        Field1 = newValue;

        Field2 = Field1 * 0.25m;

        return Task.CompletedTask;
    }
}

I think you only missed Task on the method OnField1Changed. It must be available so that Blazor can update the tree.

Also, you don't need @bind- for the readonly field.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@yangetze
Comment options

@stsrki
Comment options

@yangetze
Comment options

Answer selected by stsrki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants