MudTextField not updating then changing the text in code

I have this MudDialog component showing a MudTextField. MudTextField updates it’s text value when typing inside the text field, but it doesnt update it when modifying the value through code. would anybody happen to know why?

I have shortened the content and removed some styles and methods that I deem not relevant to this issue (such as sending or saving the email). if any more code sharing is required, I’m happy to share it.

the line in question is InputValue = string.Empty; // Clear the input field
while the method is being called, the MudTextField doesnt react at all to the value of InputValue being changed.
StateHasChanged() or InvokeAsync(StateHasChanged) dont help either. I can confirm the chip is being added successfully. What do I need to do for MudTextField to update it’s value once I change it in code?

thanks!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><MudDialog>
<TitleContent></TitleContent>
<DialogContent>
<MudGrid>
<MudItem xs="9">
<div class="email-input-container">
<MudChipSet T="string" ReadOnly="false" Class="chip-set">
u/foreach (var chip in _chips)
{
<MudChip T="string" Text="@chip" OnClose="() => RemoveChip(chip)" CloseIcon="@Icons.Material.Filled.Close" Ripple="false">
</MudChip>
}
</MudChipSet>
<MudTextField Immediate="true" u/bind-Value="InputValue" Placeholder="Enter email address and press space..." OnKeyUp="OnKeyUpHandler" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Email"/>
</div>
</MudItem>
</MudGrid>
<MudTextField u/bind-Value="SubjectTextValue" Label="Subject" Variant="Variant.Filled"/>
<br/>
<MudHtmlEditor u/bind-Html="BodyText" />
<!-- <MudTextField T="string" Variant="Variant.Outlined" Text="@BodyText" Lines="10"/> -->
<br/>
</DialogContent>
<DialogActions>
<MudButton StartIcon="@Icons.Material.Filled.Send" Color="Color.Primary" OnClick="SendEmail">Send</MudButton>
<MudButton StartIcon="@Icons.Material.Filled.Save" IconColor="Color.Secondary" OnClick="SaveMailAsDraft">Save Draft</MudButton>
<MudButton StartIcon="@Icons.Material.Filled.Delete" bColor="Color.Primary" OnClick="CloseDialog">Cancel</MudButton>
</DialogActions>
</MudDialog>
u/code {
private string InputValue { get; set; } = "";
private List<string> _chips = new List<string>();
private void OnKeyUpHandler(KeyboardEventArgs args)
{
// MyLogger.Information("Key pressed is:" + args.Key);
if (args.Key == " " && !string.IsNullOrWhiteSpace(InputValue))
{
var email = InputValue.Trim();
if (!string.IsNullOrWhiteSpace(email) && !_chips.Contains(email))
{
_chips.Add(email);
}
InputValue = string.Empty; // Clear the input field
}
}
private void RemoveChip(string chip)
{
_chips.Remove(chip);
}
}
</code>
<code><MudDialog> <TitleContent></TitleContent> <DialogContent> <MudGrid> <MudItem xs="9"> <div class="email-input-container"> <MudChipSet T="string" ReadOnly="false" Class="chip-set"> u/foreach (var chip in _chips) { <MudChip T="string" Text="@chip" OnClose="() => RemoveChip(chip)" CloseIcon="@Icons.Material.Filled.Close" Ripple="false"> </MudChip> } </MudChipSet> <MudTextField Immediate="true" u/bind-Value="InputValue" Placeholder="Enter email address and press space..." OnKeyUp="OnKeyUpHandler" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Email"/> </div> </MudItem> </MudGrid> <MudTextField u/bind-Value="SubjectTextValue" Label="Subject" Variant="Variant.Filled"/> <br/> <MudHtmlEditor u/bind-Html="BodyText" /> <!-- <MudTextField T="string" Variant="Variant.Outlined" Text="@BodyText" Lines="10"/> --> <br/> </DialogContent> <DialogActions> <MudButton StartIcon="@Icons.Material.Filled.Send" Color="Color.Primary" OnClick="SendEmail">Send</MudButton> <MudButton StartIcon="@Icons.Material.Filled.Save" IconColor="Color.Secondary" OnClick="SaveMailAsDraft">Save Draft</MudButton> <MudButton StartIcon="@Icons.Material.Filled.Delete" bColor="Color.Primary" OnClick="CloseDialog">Cancel</MudButton> </DialogActions> </MudDialog> u/code { private string InputValue { get; set; } = ""; private List<string> _chips = new List<string>(); private void OnKeyUpHandler(KeyboardEventArgs args) { // MyLogger.Information("Key pressed is:" + args.Key); if (args.Key == " " && !string.IsNullOrWhiteSpace(InputValue)) { var email = InputValue.Trim(); if (!string.IsNullOrWhiteSpace(email) && !_chips.Contains(email)) { _chips.Add(email); } InputValue = string.Empty; // Clear the input field } } private void RemoveChip(string chip) { _chips.Remove(chip); } } </code>
<MudDialog>
    <TitleContent></TitleContent>
    <DialogContent>    
        <MudGrid>
            <MudItem xs="9">
                <div class="email-input-container">
                    <MudChipSet T="string" ReadOnly="false" Class="chip-set">
                       u/foreach (var chip in _chips)
                        {
                        <MudChip T="string" Text="@chip" OnClose="() => RemoveChip(chip)" CloseIcon="@Icons.Material.Filled.Close" Ripple="false">
                        </MudChip>
                        }
                    </MudChipSet>
                    <MudTextField Immediate="true" u/bind-Value="InputValue" Placeholder="Enter email address and press space..." OnKeyUp="OnKeyUpHandler" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Email"/>
                </div>
            </MudItem>
        </MudGrid>

      
        <MudTextField u/bind-Value="SubjectTextValue" Label="Subject" Variant="Variant.Filled"/>
        <br/>
        <MudHtmlEditor u/bind-Html="BodyText"  />
        <!-- <MudTextField T="string" Variant="Variant.Outlined" Text="@BodyText" Lines="10"/> -->
        <br/>

    </DialogContent>
    <DialogActions>
        <MudButton StartIcon="@Icons.Material.Filled.Send" Color="Color.Primary" OnClick="SendEmail">Send</MudButton>
        <MudButton StartIcon="@Icons.Material.Filled.Save" IconColor="Color.Secondary" OnClick="SaveMailAsDraft">Save Draft</MudButton>
        <MudButton StartIcon="@Icons.Material.Filled.Delete" bColor="Color.Primary" OnClick="CloseDialog">Cancel</MudButton>
    </DialogActions>
</MudDialog>


u/code {

    private string InputValue { get; set; } = "";
    private List<string> _chips = new List<string>();

    private void OnKeyUpHandler(KeyboardEventArgs args)
    {
        // MyLogger.Information("Key pressed is:" + args.Key); 
        if (args.Key == " " && !string.IsNullOrWhiteSpace(InputValue))
        {
            var email = InputValue.Trim();
            if (!string.IsNullOrWhiteSpace(email) && !_chips.Contains(email))
            {
                _chips.Add(email);
            }
            InputValue = string.Empty; // Clear the input field
        }
    }

    private void RemoveChip(string chip)
    {
        _chips.Remove(chip);
    }
}

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật