Page 1 of 1

post data isn't updating

PostPosted: Mon Mar 16, 2009 3:21 pm
by colinta
I didn't see this on the forums, so this must be a rare fluke, but here it is:

Code: Select all
<form action="post">
<textarea class="wymeditor" id="profile_summary" name="profile[summary]"><?= $summary ?></textarea>
<input type="image" name="action" value="submit" src="/image/button_save_changes.gif" />

and $('.wymeditor').wymeditor(); in the page load function()

The editor appears, but after modifying the text and pressing 'save', the post data contains the OLD text, not the new text. Even weirder, I can force the textarea to update if I toggle the html-code editor.

Has anyone had this problem? What's wrong here? Is it the <input type="image" /> tag?

I'm using jQuery 1.3, wymeditor 0.5 beta 2 (11/15/2008), Firefox 3 on Mac OS X

Re: post data isn't updating

PostPosted: Mon Mar 16, 2009 3:47 pm
by mr_lundis
You'll need to add the class "wymupdate" to the submit button or set the update selector/event - it's all in the documentation. ;) ... pdateEvent


Re: post data isn't updating

PostPosted: Fri Apr 03, 2009 4:00 pm
by elKrys

First I'd like to congratulate you for all this work - until now I used to work with Tiny MCE, and... well...

But, alas, I have the same problem on some of the pages of the system I use - except there is a tweak.
In fact, due to reasons I can't explain (and can't change), the submit button of the form containing the WYMeditor textarea is outside the form, as follow :

Code: Select all
<form name="myform" method="post" action="...">
<textarea class="wymeditor" name="section_contenu"></textarea>
<!-- The rest of the page -->
<button class="wymupdate" onclick="save()">Save</button>

And when I'm in this situation, neither the "wymupdate" class on the button, nor the "update selector/event" method work. Each time the post data doesn't update.

Would you happen to know a solution to this problem ? (given I can't put a submit button in the form)

Thanks in advance.

P.S. : As you may have guessed, I'm not English, nor english-speaking, so excuse my -I hope few- mistakes
P.P.S. : I'm using wymeditor 0.5 beta 2 (downloaded 04/01/2009) and - mostly - IE7/8

Re: post data isn't updating

PostPosted: Mon Apr 20, 2009 10:53 am
by mr_lundis
Hello elKrys, and welcome to the WYMeditor forum!

Call the update() method of your WYMeditor instance before you serialize/submit the form to make WYMeditor update the replaced textarea.
Code: Select all
function save() {
    // Some code goes here...

    var wym =jQuery.wymeditors(0);

    // The code for saving/serializing the form/whatever goes here

Cheers! ;)

Re: post data isn't updating

PostPosted: Wed Jun 30, 2010 7:57 pm
by nicoechaniz
I needed to be able to toggle WYMEditor On and Off in the django admin.

I ended up with this code, which is an adaptation of snippets I came across. This approach will let you turn it on and off while preserving whatever content changes you have made in each mode and will modify the submit button event bindings to support saving with the editor enabled or disabled

I'm copying the whole file content as we use it in the Cyclope CMS project[0].

Code: Select all
from django import forms
from django.utils.safestring import mark_safe
from django.conf import settings
from django.utils.translation import ugettext as _

from cyclope import settings as cyc_settings

class WYMEditor(forms.Textarea):
    """Widget to replace a standard textarea with WYMEditor"""
    class Media:
        js = (
            cyc_settings.CYCLOPE_MEDIA_URL +'js/reuse_django_jquery.js',
            cyc_settings.CYCLOPE_MEDIA_URL +'js/jquery.wymeditor.filebrowser.js',
            cyc_settings.CYCLOPE_MEDIA_URL +'js/wymeditor/jquery.wymeditor.pack.js',

    def __init__(self, language=None, attrs=None):
        self.language = language or settings.LANGUAGE_CODE[:2]
        self.attrs = {'class': 'wymeditor'}
        if attrs:
        super(WYMEditor, self).__init__(attrs)

    def render(self, name, value, attrs=None):
        editor_toggle = '''
            <p style="clear:both; margin: 0px; padding: 0 0 5px 0;">
            <select class="wymtoggle">
                <option value="on">%s</option>
                <option value="off">%s</option>
            ''' % (_('toggle editor'), _('on'), _('off') )
        rendered = super(WYMEditor, self).render(name, value, attrs)
        return mark_safe(editor_toggle) + rendered + mark_safe(u'''
            <script type="text/javascript">
                updateSelector: '.submit-row input[type=submit]',
                updateEvent: 'click',
                lang: '%s',
                postInitDialog: wymeditor_filebrowser,
                postInit: function(wym){
                    //Set the 'Toggle' select
                    jQuery('.wymtoggle').change( function() {
                        if(jQuery(this).val() == 'on') {
                            jQuery('.submit-row input[type=submit]').click(function(){wym.update();})
                        } else {
                            jQuery('.submit-row input[type=submit]').unbind();
            % (name, self.language, name, name, name))