1

我们在我们的 angular4 应用程序中使用 froala 编辑器,我在尝试验证编辑器的内容时​​遇到了困难。基本上我们要禁止在编辑器中只输入空格、制表符或输入字符的用户。

我尝试了以下代码但没有成功:

options: Object = {
  placeholderText: '',
  height: 300,
  charCounterMax: 3000,
  htmlAllowedEmptyTags: [],
  events : {
    'froalaEditor.blur' : function(e, editor) {
      editor.html.unwrap();
      editor.html.cleanEmptyTags();
      console.log("'" + editor.html.get() + "'");
    }
  }
}

无论我在做什么,我仍然得到

'<p>&nbsp;&nbsp;</p>' 

当用户输入两次空格键并验证时。是否有任何修剪功能或类似功能?多谢

4

1 回答 1

0

您可以使用该innerText属性并自己修剪内容。

配置

const buttonConfig = ['bold', 'italic', 'underline', '|', 'formatOL', 'formatUL', '|', 'insertLink', '|', 'undo', 'redo'];
this.options = {
  charCounterCount: true,
  key: environment.froalaLicenseKey,
  language: 'de',
  charCounterMax: this.maxLength,
  toolbarButtons: buttonConfig,
  toolbarButtonsSM: buttonConfig,
  toolbarButtonsXS: buttonConfig,
  placeholderText: this.placeholder,
  pluginsEnabled: ['link', 'lists', 'charCounter'],
  linkAlwaysBlank: true,
  linkInsertButtons: ['linkBack'],
  linkEditButtons: ['linkOpen', 'linkEdit', 'linkRemove'],
  zIndex: 9999,
  events: {
    /*on every blur event check if the user has actually inserted content and clean if needed*/
    'froalaEditor.blur': (e: FocusEvent, editor) =>  (editor) => {
      let t = document.createElement('div');
      t.innerHTML = editor.html.get();
      let trimmedText = t.innerText.trim();
      if (!trimmedText) {
        editor.html.set('');
        editor.events.trigger('charCounter.update');
      }
    },
  },
};
于 2018-09-06T15:59:46.873 回答