Forum closed. New forum available at http://community.wymeditor.org/

post data isn't updating

Support forum for WYMeditor.

post data isn't updating

Postby colinta on Mon Mar 16, 2009 3:21 pm

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" />
</form>


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
colinta
 
Posts: 1
Joined: Mon Mar 16, 2009 3:08 pm

Re: post data isn't updating

Postby mr_lundis on Mon Mar 16, 2009 3:47 pm

You'll need to add the class "wymupdate" to the submit button or set the update selector/event - it's all in the documentation. ;)

http://trac.wymeditor.org/trac/wiki/0.5/Integration
http://trac.wymeditor.org/trac/wiki/0.5 ... pdateEvent

Cheers!
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: post data isn't updating

Postby elKrys on Fri Apr 03, 2009 4:00 pm

Hello,

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>
</form>
<!-- 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
elKrys
 
Posts: 1
Joined: Fri Apr 03, 2009 3:47 pm

Re: post data isn't updating

Postby mr_lundis on Mon Apr 20, 2009 10:53 am

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);
    wym.update();

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


Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: post data isn't updating

Postby nicoechaniz on Wed Jun 30, 2010 7:57 pm

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:
            self.attrs.update(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;">
            %s:
            <select class="wymtoggle">
                <option value="on">%s</option>
                <option value="off">%s</option>
            </select>
            </p>
            ''' % (_('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">
            jQuery('#id_%s').wymeditor({
                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') {
                            wym.html(jQuery('#id_%s').val());
                            jQuery('.wym_box').show();
                            jQuery('#id_%s').hide();
                            jQuery('.submit-row input[type=submit]').click(function(){wym.update();})
                        } else {
                            wym.update();
                            jQuery('.wym_box').hide();
                            jQuery('#id_%s').show();
                            jQuery('.submit-row input[type=submit]').unbind();
                        }
                    });
                }
            });
            </script>
            '''
            % (name, self.language, name, name, name))



cheers,

NicoEchániz

[0] http://codigo.cyclope.ws
nicoechaniz
 
Posts: 2
Joined: Wed Jun 30, 2010 7:45 pm


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests