[英]Input field text validation failing for summernote text area
I am using Summernote for rich text editing.我正在使用 Summernote 进行富文本编辑。 My input field has the required attribute.我的输入字段具有必需的属性。
<input
required
id="summernote"
formControlName="description"
[ngxSummernote]="config"
/>
I have the Submit button.我有提交按钮。 It will be disabled if the the text area is empty or pristine or invalid.如果文本区域为空、原始或无效,它将被禁用。 code below.下面的代码。
<button
mat-raised-button
class="btn btn-danger pull-right"
type="submit"
(click)="submitDoc()"
[disabled]="
questionFormGroup.pristine || questionFormGroup.invalid
"
>
Post Question
</button>
If I copy-paste some text inside my summernote editor, the button will get enable But if I do ctrl+a and remove all the text present inside text editor, the button should be disabled since there is no text inside text-area.如果我在summernote编辑器中复制粘贴一些文本,按钮将启用但如果我执行ctrl + a并删除文本编辑器中存在的所有文本,则应禁用该按钮,因为文本区域内没有文本。 If I submit the form, the text are will contain values like below:如果我提交表单,文本将包含如下值:
<br><div>
</div><div>
</div><div>
</div><div>
</div><div>
</div><div>
</div><div>
</div><div>
</div><div>
</div><div>
How do I resolve this wrt to summernote.我如何解决这个问题到summernote。 Button enabled image here and text area contents here.此处启用按钮的图像和此处的文本区域内容。
Here is my formGroup:这是我的表单组:
createQuestionFormGroup(): void {
this.questionFormGroup = this.formBuilder.group({
heading: undefined,
description: undefined,
});
}
There is a problem after pasting content directly inside ngxSummernote
library textbox isn't updating the form control touched
/ pristine
state of the formControl
.将内容直接粘贴到ngxSummernote
库文本框中后出现问题,没有更新 formControl 的touched
/ pristine
formControl
的表单控件。
To fix the issue you can implement onPaste
callback function inside config
's callbacks
option.要解决此问题,您可以在config
的callbacks
选项中实现onPaste
回调 function 。
config = {
...,
callbacks: {
onPaste: (ne) => {
var bufferText = (ne.originalEvent || ne).clipboardData.getData('Text');
if (bufferText) {
// calling onTouched method to set formControl touched/pristine state update.
this.summernote.onTouched();
}
},
},
};
isEmpty
Returns whether editor content is empty or not.返回编辑器内容是否为空。 You can implement this method to check contents.您可以实现此方法来检查内容。
The editing area needs <p><br></p>
for focus, even if the editor content is empty.编辑区域需要<p><br></p>
获得焦点,即使编辑器内容为空。 So Summernote supports this method for helping to check if editor content is empty.所以 Summernote 支持这种方法来帮助检查编辑器内容是否为空。
if ($('#summernote').summernote('isEmpty')) {
alert('editor content is empty');
}
Here is another way of resolving your particular issue.这是解决您的特定问题的另一种方法。 Collect the HTML that is present inside your Summernote text-area using使用以下方法收集 Summernote 文本区域中存在的 HTML
var text = $('#body-summernote').summernote('code');
Strip off the HTML tags present in the var text.去掉 var 文本中存在的 HTML 标签。
$(text).text()
You'll get rid of all the tags like and您将摆脱所有标签,例如和
$(text).text().trim().length > 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.