[英]Blazor Text Editor not able to bind value on form (create/edit)
I am using Blazor Text Editor from source below.我正在使用来自以下源的 Blazor 文本编辑器。
Source - https://github.com/Blazored/TextEditor来源 - https://github.com/Blazored/TextEditor
I successfully integrated it with my create and edit form, however not able to bind-Value to it.我成功地将它与我的创建和编辑表单集成,但无法将值绑定到它。 Because of this my Data Annotation Validation is failing.
因此,我的数据注释验证失败。
Internally blazor is using Quill Editor, I am not looking for javascript option.内部 blazor 正在使用 Quill 编辑器,我不是在寻找 javascript 选项。
Sample Code of editor编辑器示例代码
<BlazoredTextEditor @ref="@QuillNative" Placeholder="Enter non HTML format like centering...">
<ToolbarContent>Some editor stuff here</ToolbarContent>
<BlazoredTextEditor
Could anyone please help me.谁能帮帮我。 How to bind-Value or correct approach without javascript.
如何在没有 javascript 的情况下绑定值或更正方法。
Vencovsky - thanks of you prompt response, I was already aware of these methods however was curious to know if anybody had tried different option. Vencovsky - 感谢您的及时回复,我已经知道这些方法,但是很想知道是否有人尝试过不同的选择。
Below is what I did..下面是我做的..
FORM -- This is common form for create & edit. FORM - 这是创建和编辑的常用表单。 OnValidSubmit will call respective Create/Edit method.
OnValidSubmit 将调用相应的 Create/Edit 方法。
<EditForm Model="Entity" class="contact-form" OnValidSubmit="OnValidSubmit">
//My form fields here
//Commented the validation from that particular field
@*<ValidationMessage For="@(() =>Entity.field)" />*@
<div class="col-sm-1">
<button type="submit" @onclick="***getEditorData***" class="btn"
style="border:2px solid #555555;"><span>Save</span></button>
</div>
</EditForm>
METHOD -- getEditorData() gets fired before OnValidSubmit()方法 -- getEditorData() 在 OnValidSubmit() 之前被触发
public async void getEditorData()
{
Enity.field = await this.QuillNative.GetHTML();
}
So in my final Entity on OnValidSubmit() I receive all fields along with editor data..因此,在 OnValidSubmit() 上的最终实体中,我收到所有字段以及编辑器数据。
Hope this help if anyone is trying to do so..如果有人试图这样做,希望这会有所帮助..
Apparently you can't bind a value to it, but you should use the provided methods显然你不能绑定一个值,但你应该使用提供的方法
Methods方法
To use these methods you need a reference of it要使用这些方法,您需要它的参考
@* Getting the BlazoredTextEditor reference*@
<BlazoredTextEditor @ref="@BlazoredTextEditorRef">
@* rest of the code*@
</BlazoredTextEditor>
And in some code in your class you can do在你的 class 的一些代码中你可以做
void LoadData(){
//var html = BlazoredTextEditor.LoadHTML(SomeDataToLoad)
BlazoredTextEditor.LoadText(SomeDataToLoad)
}
void ValidateData(){
//var html = BlazoredTextEditor.GetHTML()
var text = BlazoredTextEditor.GetText()
// do something to validate text
}
You can call these methods and use the referece in other methods, this is just an example on how to do it.您可以调用这些方法并在其他方法中使用引用,这只是一个示例。
here is how I did this: 1- to bind the value on load:我是这样做的: 1- 绑定加载值:
<BlazoredTextEditor @ref="@QuillHtml">
<EditorContent>
@((MarkupString)infoBlock.Description)
</EditorContent>
</BlazoredTextEditor>
to get value on submit在提交时获得价值
<EditForm Model="infoBlock" OnValidSubmit="LocalOnValidSubmit">
... ...
@code {.... [Parameter] public EventCallback OnValidSubmit { get; set; } BlazoredTextEditor QuillHtml = new BlazoredTextEditor(); private async Task LocalOnValidSubmit() { infoBlock.Description = await this.QuillHtml.GetHTML(); await OnValidSubmit.InvokeAsync(this);//to call event handler passed by parent after the HTML prepared for main bound class } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.