I am attempting to use a blazorise RichTextEdit component within a form. I cannot seem to get the value to be set initially to the value of a provided model property.
<Form Model="@company">
<Validations @ref="validations" Mode="ValidationMode.Auto" ValidateOnLoad="false" Model="@model">
<Validation>
<Field>
<FieldLabel>Company Website</FieldLabel>
<TextEdit Role="TextRole.Url" @bind-Text="@model.Property1" Placeholder="Enter your website" Size="Size.Large">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Field>
</Validation>
<Field>
<FieldLabel>About</FieldLabel>
<RichTextEdit @ref="richTextEditRef"
ContentChanged="@OnContentChanged"
Theme="RichTextEditTheme.Snow"
PlaceHolder="Tell us about the company..."
SubmitOnEnter="false"
ToolbarPosition="Placement.Top">
<Editor></Editor>
<Toolbar>
<RichTextEditToolbarGroup>
<RichTextEditToolbarButton Action="RichTextEditAction.Bold" />
<RichTextEditToolbarButton Action="RichTextEditAction.Italic" />
<RichTextEditToolbarSelect Action="RichTextEditAction.Size">
<RichTextEditToolbarSelectItem Value="small" />
<RichTextEditToolbarSelectItem Selected="true" />
<RichTextEditToolbarSelectItem Value="large" />
<RichTextEditToolbarSelectItem Value="huge">Very Big</RichTextEditToolbarSelectItem>
</RichTextEditToolbarSelect>
<RichTextEditToolbarButton Action="RichTextEditAction.List" Value="ordered" />
<RichTextEditToolbarButton Action="RichTextEditAction.List" Value="bullet" />
</RichTextEditToolbarGroup>
<!-- Custom toolbar content -->
<RichTextEditToolbarGroup Float="Float.Right">
</RichTextEditToolbarGroup>
</Toolbar>
</RichTextEdit>
</Field>
</Validations>
<Button Color="Color.Success" Clicked="@Submit">Save</Button>
</Form>
@code {
private Model model { get; set; } = new Model();
private RichTextEdit richTextEditRef;
Validations validations;
protected override async Task OnInitializedAsync()
{
model = await modelService.GetByAccount();
//await richTextEditRef.SetHtmlAsync(model.Property2);
}
public async Task OnContentChanged()
{
model.Property2 = await richTextEditRef.GetHtmlAsync();
}
async void Submit()
{
Console.WriteLine("Form Submitted");
var result = await modelService.Post(model);
}
}
The modelService only returns a single record, which id does successfully. I am able to retrieve the input value using richTextEditRef.GetHtmlAsync()
however I cannot find a way to use the
richTextEditRef.SetHtmlAsync(company.About)
method to initially set the value of the RichTextEdit.
I have tried calling it after calling the modelService as seen in the commented code, but this is inconstant as it is often excecuted prior to the service returning the record. I have also attempted overriding the OnAfterRenderAsync
method but I am not sure I am doing that correctly.
Too much wasted time on this, please help!?