Skip to content

Instantly share code, notes, and snippets.

@tingwei628
Last active August 29, 2015 14:27
Show Gist options
  • Save tingwei628/f6d370bf0cc4843ad775 to your computer and use it in GitHub Desktop.
Save tingwei628/f6d370bf0cc4843ad775 to your computer and use it in GitHub Desktop.
[JavaScript][ExtJS] Htmleditor validation (like allowBlank:false)
/* IsValid() 驗證htmleditor 的 value值是否空白,並會排除空白情況
*/
//validate htmleditor
function IsValid(value) {
var div = document.createElement('div'), text;
div.innerHTML = value;
text = div.textContent || div.innerText || "";
return (text.replace(/^\s+|\s+$/gm, '') != "");
}
if(IsValid(Ext.getCmp('edit_Content').getValue())){
Ext.getCmp('edit_Content').iframeEl.setStyle({ border: '1px solid #cf4c35' }); //red border style
edit_Content.iframeEl.dom.setAttribute('data-errorqtip', '請填寫內容'); //warning tooltip
}
else{
Ext.getCmp('edit_Content').iframeEl.setStyle({ border: '' });
edit_Content.iframeEl.dom.setAttribute('data-errorqtip', '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment