Page 1 of 1

Multiple submit buttons?

PostPosted: Mon Oct 13, 2008 11:02 pm
by michaele
I am using wymeditor in a CMS that is based on jQuery.

This code sets up wymeditor on any textarea with the class "richtextarea"

$('textarea.richtextarea').wymeditor({
updateSelector: "#submitbutton, #submittomail",
updateEvent: "click"
});

In theory, this should cause both the submitbutton and the submittomail button to update wymeditor and submit the form.
However, in this usage, only the first one, submitbutton, does what it should.

The difference is that 'submitbutton' is a "submit" input type, while 'submittoemail' is a "button" input type, with the submission action for the form added via jquery.

$('#submittomail').click(function(){
// other stuff here
$('.admin-form').submit();
});

This seems to cause the form to be submitted before the wymeditor source is updated.
If I change it to a "submit" type , it updates wymeditor as it should, before submitting the form.
But then I have another problem, clicking 'enter' in any field causes the second submit button to be clicked - it should use the current 'submit' button.
This is why I have the other button as a 'button' with the submit added dynamically.

So I either need to force wymeditor to accept the 'button' as an update handler, or add some code before the 'submit()' for the click function, that updates wymeditor then submits the form.

I am open to any change that will make this work the way I need... any ideas?

Re: Multiple submit buttons?

PostPosted: Wed Oct 15, 2008 5:46 pm
by mr_lundis
Hi Michaele, and welcome to the WYMeditor forum!

First of all I'm sorry for the late response. I've however done some thinking, and I can't find any obvious mistakes or errors in your submitted code. Is it possible that you could set up a test page for us? That would make it a lot easier to find the cause of you problems.

Thanks. ;)

Re: Multiple submit buttons?

PostPosted: Thu Oct 16, 2008 6:09 pm
by jfh
If you know the WYMeditor instance index (usually 0, if there's just one instance in the page), you can use the update() API call like this:
Code: Select all
jQuery.wymeditors(0).update();

jQuery.wymeditors examples are available in the Test Suite HTML source.

Re: Multiple submit buttons?

PostPosted: Thu Oct 23, 2008 8:12 am
by michaele
@jfh: Thanks SO much - that did the trick perfectly!

>> jQuery.wymeditors(0).update();
or $.wymeditors(0).update();

this does exactly what I needed.
:D

Curious, is there a way to use that same method on multiple wym's ?

( Could you first check the DOM for the number of instances, then loop through and update each by number?
Or maybe a more elegant way?)

thanks for the help, really a time saver.