This is a migrated thread and some comments may be shown as answers.

refreshes other controls

1 Answer 182 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Veteran
Rick asked on 21 Jun 2019, 04:56 PM

Scenario:

I have a window that I am using to edit values, has textboxes, the dropdown, and other controls.

Window is opened, textbox loads with the bound value, lets say value = 100.

Change the textbox to say maybe 101.

Select a new dropdown option.

After the dropdown selection is chosen and it's new value binds, it resets the other controls to the original value, so the 101 is back to 100.

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 Jun 2019, 11:11 AM
Hello Rick,

How are those fields bound? Is the following snippet close to your scenario, because it seems to work fine for me? Can you modify it to showcase the problem so I can examine it?

@using Telerik.Blazor.Components.Window
@using Telerik.Blazor.Components.DropDownList
@using Telerik.Blazor.Components.NumericTextBox
@using System.ComponentModel.DataAnnotations
 
<TelerikWindow Visible="true" Height="400px">
    <TelerikWindowTitle>
        <strong>The Title</strong>
    </TelerikWindowTitle>
    <TelerikWindowContent>
        <EditForm Model="@person" OnValidSubmit="@HandleValidSubmit">
            <DataAnnotationsValidator />
            <ValidationSummary />
            <p class="age">
                Age: <TelerikNumericTextBox @bind-Value="person.Age"></TelerikNumericTextBox>
                <ValidationMessage For="@(() => person.Age)"></ValidationMessage>
            </p>
            <p class="gender">
                Gender: <TelerikDropDownList @bind-Value="person.Gender" DefaultItem="@ddlHint"
                                         Data="@genders" TextField="MyTextField" ValueField="MyValueField">
                </TelerikDropDownList>
                <ValidationMessage For="@(() => person.Gender)"></ValidationMessage>
            </p>
 
            <button type="submit">Submit</button>
        </EditForm>
    </TelerikWindowContent>
</TelerikWindow>
 
 
 
 
@code {
    // Usually the model classes would be in different files
    public class Person
    {
        [Required(ErrorMessage = "Gender is mandatory.")]//the value field in the dropdown model must be null in the default item
        [Range(1, 3, ErrorMessage = "Please select your gender.")] //limits the fourth option just to showcase this is honored
        public int? Gender { get; set; }
 
        [Required]
        public int Age { get; set; }
    }
 
    public class MyDdlModel
    {
        //nullable so the default item can allow required field validation
        //alternatively, use a range validator and put a value out of that range for the default item
        public int? MyValueField { get; set; }
        public string MyTextField { get; set; }
    }
 
    Person person = new Person();
 
    MyDdlModel ddlHint = new MyDdlModel { MyValueField = null, MyTextField = "Gender" };
 
    IEnumerable<MyDdlModel> genders = new List<MyDdlModel>
{
        new MyDdlModel {MyTextField = "female", MyValueField = 1},
        new MyDdlModel {MyTextField = "male", MyValueField = 2},
        new MyDdlModel {MyTextField = "other", MyValueField = 3},
        new MyDdlModel {MyTextField = "I'd rather not say", MyValueField = 4}
    };
 
    void HandleValidSubmit()
    {
        Console.WriteLine("OnValidSubmit");
    }
}


Regards,
Marin Bratanov
Progress Telerik UI for Blazor
Tags
DropDownList
Asked by
Rick
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Share this question
or