Own form widget - close event not fired ? [message #1828212] |
Thu, 04 June 2020 04:08  |
Eclipse User |
|
|
|
Hi.
I created my own form widget:
fitbig.TinyMCEForm = function() {
fitbig.TinyMCEForm.parent.call(this);
};
scout.inherits(fitbig.TinyMCEForm, scout.Form);
fitbig.TinyMCEForm.prototype._render = function() {
alert('_render');
this._renderForm();
};
fitbig.TinyMCEForm.prototype._close = function() {
alert('_close');
}
In Java Form I have this construction:
@ModelVariant("fitbig.TinyMCE")
public class HtmlEditorForm extends AbstractForm {
When form is displayed, then "_render" method is fired - alert box is showed.
But when form is closed (via OkButton, or via CancelButton), then "_close" method is not fired - alert box is not shown.
I need run some javascript code where form is closed.
Can anyone advise me?
Thank you.
|
|
|
|
|
|
Re: Own form widget - close event not fired ? [message #1828395 is a reply to message #1828219] |
Tue, 09 June 2020 03:40   |
Eclipse User |
|
|
|
Hello.
I have one more question. I modified the call in the new widget as follows:
fitbig.TinyMCEForm = function() {
fitbig.TinyMCEForm.parent.call(this);
};
scout.inherits(fitbig.TinyMCEForm, scout.Form);
fitbig.TinyMCEForm.prototype._render = function() {
this._renderForm();
window.tinymce.init({selector: '.tinymce textarea'});
};
fitbig.TinyMCEForm.prototype._remove = function() {
alert(window.tinymce.activeEditor.getContent()); // This works, editor content is displayed.
var tinymcefield = scout.getSession().desktop.activeForm.rootGroupBox.fields[2];
tinymcefield.setValue(window.tinymce.activeEditor.getContent()); // No error, but form field has no value
document.cookie = 'TinyMCEFormResult='+window.tinymce.activeEditor.getContent(); // Cookie is right set, but I can't read it in Java.
// Default code from Form.js
this.formController.remove();
this.messageBoxController.remove();
this.fileChooserController.remove();
if (this._glassPaneRenderer) {
this._glassPaneRenderer.removeGlassPanes();
this._glassPaneRenderer = null;
}
this._uninstallFocusContext();
this.$statusIcons = [];
this.$header = null;
this.$statusContainer = null;
this.$close = null;
this.$saveNeeded = null;
this.$icon = null;
this.$title = null;
this.$subTitle = null;
scout.Form.parent.prototype._remove.call(this);
}
Using the form in Java:
HtmlEditorForm form = new HtmlEditorForm(); // In this form is used widget.
form.startNew();
form.waitFor();
//String result = CookieUtility.getCookieByName(req, cookieName) // Can't read cookie, I can't get current http request
MessageBoxes.createOk().withBody(form.getContentField().getValue()).show(); // Display empty value
_render works fine - TinyMCE editor is shown and work.
Unfortunately, I can't transfer its contents to a form field. In _remove alert show editor content, I try set value to formfield or set cookie value. Setting value not work, cookie I can't read in Java.
It's hard for me to figure it out on my own, but I need to use TinyMCE (or some other WYSIWYG editor) in the form.
Can anyone advise me? How do I fill the value of a form field in Javascript? Or how do I read the value of a cookie in Java? Or some better solution?
Thank you.
|
|
|
Re: Own form widget - close event not fired ? [message #1828411 is a reply to message #1828395] |
Tue, 09 June 2020 06:38  |
Eclipse User |
|
|
|
As I said, first you need to understand the basic concepts of Scout and how to build a custom widget with Scout. I'd recommend to analyze the HeatMap-widget (see this thread here).
When you have a TinyMCEField this field alone should be responsible to initialize and render/remove the TinyMCE Editor (basically it works like a more sophisticated StringField). You should not require a special Form to deal with TinyMCE. This means the TinyMCEField also must set the value and must synchronize the value in the browser with the model on the UI-server using Scout's JSON protocol. The HeatMap widget is a good starting point to understand which parts (like the JSON layer) are required. I'd also recommend to start up the Dev-Tools in your browser, open the Network tab and analyze what happens when you type something into a StringField. Exactly the same thing should happen, when your TinyMCEField updates the value on the UI-Server (or must render a value set by the UI-Server).
Sending the value via Cookie looks like a conceptual error to me.
[Updated on: Tue, 09 June 2020 08:24] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.08119 seconds