简体   繁体   中英

How to refresh a PrimeFaces Editor component from JavaScript

I have a PrimeFaces (2.2.1) Editor on a page where I want to allow the user to append text to the editor by selecting a value from a drop-down list and pressing a button indicating that they want it appended to the text. I can add the text to the editor using JavaScript like this:

document.getElementById('form:editor').value = document.getElementById('form:editor').value + 'NEW TEXT!';

However, unlike an inputTextarea, the PrimeFaces Editor component doesn't refresh automatically when its value is changed. I have to press the browser's reload button or hit the editor's Show Source button to get the appended text to display. Is there anything I can do from JavaScript to get the editor to refresh itself after changing its value?

Not a good solution, but it should work.

editorWidgetVar.jqInput.var()

stores a value which would be submited on a form submit.

$(editorWidgetVar.jq.find('iframe')[0].contentDocument).find('body').html()

but this is actually visible for user element. So if you want to change content of editor, then you should change both fields (hidden for proper submitting and visible for proper display). I am almost sure there is a normal API for it. This method would be good for a temporary workaround.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM