Opened 14 years ago

Closed 11 years ago

#254 closed enhancement (fixed)

make a hook for plugins to use on form submit event

Reported by: anonymous Owned by: gogo
Priority: low Milestone:
Component: Xinha Core Version:
Severity: normal Keywords:


A thing I have encountered is the need to hook up to htmlarea onsubmit event from the plugin. Since there is no way to do this, I had to apply an ugly hack in the plugin.

A much better way would be to make it possible for plugins to register for an onsubmit event somehow. Shouldn't be hard to implement really.

Change History (6)

comment:1 Changed 14 years ago by anonymous

  • Severity changed from normal to enhancement

comment:2 Changed 14 years ago by niko

could this be done using the notifyOn and notifyOf functions?

i have never used them nor looked at them in detail... perhaps i could get some short explanation and where we should use them from gogo :D

comment:3 Changed 14 years ago by gogo

Those functions are sort of "fake events", not real events because I found that using "custom events" just was a big pain. Essentially something can register to be "notified on" some event happening (say the editor gets resized), and then something else can "notify of" that event.

Now, as for the submitter, what is it that you want to do onsubmit, that would help determine where it's best to go.

comment:4 Changed 14 years ago by troels_kn

Those functions are sort of "fake events", not real events because I found that using "custom events" just was a big pain.

I'm not sure about the details, but being a very very flexible language, I'm sure that it's possible to create and propagate custom events the same way as "real" events. Alternatively, we could create an event-api between the editor and the plugins. Is this what you're referring to with the "custom events" above ?

Specifically I had the need to run plugin at form submit-time. This is particularily tricky, since it may be important if the event is triggered last or first in the que (given there are more). This should count in favour of creating a custom eventhandling mechanism. No need to reinvent the wheel though, since this has already been tinkered with by other people. (I have some links lying around somewhere, I can dig up if need be)

I used an event on submittime for my plugin, in order to transform the "working" document into a "clean" document. Have a look at the Indite project for a better understanding of the mechanism, but basically I use xslt to enforce a certain semantical ruleset for the document at runtime. Much like htmltidy or some of the word-paste-cleaners around, except it's based on xsl + dtd and it's realtime.

Also, if I recall it correctly, I had some troubles with "paste", "dragdrop", "drop" and "resizeend" since the method HTMLArea._addEvents() should be fed with editor._iframe.contentWindow.document.body under IE and just editor._iframe.contentWindow.document under mozilla. That sort of browser-incompatibility could also be sorted out by using a custom eventhandler.

comment:5 Changed 14 years ago by gogo

  • Milestone Version 1.0 deleted
  • Priority changed from normal to low

As of changeset:177 you could use something like

HTMLArea.addDom0Event(editor._textArea.form, 'submit', yourHandlerHere)

which will fire after the content is placed into the textarea when the form is submitted (and BEFORE any <form onsubmit="blah" > is run), and.

HTMLArea.prependDom0Event(editor._textArea.form, 'submit', yourHandlerHere)

which, provided you do that after editor.generate() has completed (so do it onGenerate() in your plugin), will run BEFORE the content is placed into the textarea.

Ensure that you return true from the handlers to allow other events to fire (unless you don't want them to, then return false).

Leaving open at low priority because we probably should add a onPreSubmit and onPostSubmit or something for plugins to use.

comment:6 Changed 11 years ago by ray

  • Resolution set to fixed
  • Status changed from new to closed

there is a


if ever the need arises to have an post submit this could easily be added.

Note: See TracTickets for help on using tickets.