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

Update content with Ajax

Support forum for WYMeditor.

Update content with Ajax

Postby wolfgang on Wed May 28, 2008 6:01 pm

Hi,
i read some post about update the wymeditor content via ajax.
But i dont understand it realy.
The wiki say(http://trac.wymeditor.org/trac/wiki/0.5/API):
wym.html("<p>Hello, World.</p>");

But how do i define wym?

My code looks like this (Changed on 31.05):
Code: Select all
$(document).ready(function(){
    wedit = new Array();
    var wedit = $("#ProductDesc").wymeditor({ lang: 'de', });
    alert (wedit[0]);
   
    $("[name=cTProduct_id]").click(function()
    {
        $.post("forms/product_getData.php",{ product_id:$("[name=cTProduct_id]").val(),rand:Math.random() } ,
            function(data){
                wedit[0].html(data);
           });
    });
    $("[name=cTCategory_id]").change(function()
    {
        $("#FormProduct").submit();
    });
    $("[name=cTType_id]").change(function()
    {
       $("#FormProduct").submit();
    });
});


What do i wrong?
Thanks
Last edited by wolfgang on Sat May 31, 2008 6:25 am, edited 2 times in total.
wolfgang
 
Posts: 5
Joined: Wed May 28, 2008 5:39 pm

Re: Update content with Ajax

Postby mr_lundis on Thu May 29, 2008 3:23 pm

The wym variable in the docs correspond to your current WYM instance. You can set the wym variable like this:
Code: Select all
var wym = jQuery.wymeditors(youInstace);
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: Update content with Ajax

Postby wolfgang on Thu May 29, 2008 4:00 pm

Thanks,
im realy new to java script and jquery.
var wym = jQuery.wymeditors($("#ProductDesc")); is it not.
Does $("#ProductDesc").wymeditor({ ... not produce a instance of the editor?

Sorry and thank you a lot.
wolfgang
 
Posts: 5
Joined: Wed May 28, 2008 5:39 pm

Re: Update content with Ajax

Postby mr_lundis on Thu May 29, 2008 7:47 pm

You're welcome, maybe I could have been a lite bit clearer as well...

WYMeditor stores it's instances in an numerical aray, so it's the array offset that you should use. I know that this kinda sucks, and I'll probably post an enhancement ticket about this at the trac site, whenever I'll find some time over.

And to answer you question, $("<selector>").wymeditor(); does create a new instance of the editor, however it doesn't return any reference to that instance.
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: Update content with Ajax

Postby jfh on Fri May 30, 2008 8:25 pm

I guess it will be easier for you to put the 'wymupdate' class to the 'cTProduct_id' element, and get the content from #ProductDesc.

HTH
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium

Re: Update content with Ajax

Postby wolfgang on Sat May 31, 2008 6:23 am

I'm totally lost.
What i think to know is this:
With $("#ProductDesc").wymeditor({ lang: 'de', });
i get an instance of wymeditor for #ProductDesc.
Wymeditor does not return the instance, it returns an index of it.
I think this is because i can have multiply instance (if i use class and not id).

My problem is to work with this instance.
I change the code of my first post to the one i now have:
I declare wedit as array and allert show me [object HTMLTextAreaElement]
but wedit[0].html(data); produce an error: wedit[0].html is not a function
I misunderstand any think.
wolfgang
 
Posts: 5
Joined: Wed May 28, 2008 5:39 pm

Re: Update content with Ajax

Postby mr_lundis on Sun Jun 01, 2008 7:34 pm

To get a wym instance reference do like this:
Code: Select all
// To get the instance #1 (0)
var wym = jQuery.wymeditors(0);
// To get the instance #2
var wym = jQuery.wymeditors(1);
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: Update content with Ajax

Postby wolfgang on Sat Jun 07, 2008 6:41 pm

It works.
ok, () not [] :-)
Thank you a lot mr_lundis!
wolfgang
 
Posts: 5
Joined: Wed May 28, 2008 5:39 pm

Re: Update content with Ajax

Postby x-f on Tue Aug 19, 2008 7:09 pm

Is there a way to get the current instance of WYMeditor?
I've made my own button, which opens a popup window with images user can click on to insert the image. It works.
But in order to get the WYMeditor instance, where to insert the HTML code, I must use
Code: Select all
var wym = window.opener.WYMeditor.INSTANCES[1];

The problem is – I have two instances of WYMeditor on one page, and I don't know which one of them user is currently using.

Is this possible?
I went a couple of times through the jquery.wymeditor.js, but couldn't figure it out by myself.
x-f
 
Posts: 1
Joined: Mon Aug 18, 2008 12:40 pm

Re: Update content with Ajax

Postby mr_lundis on Thu Aug 21, 2008 5:07 pm

x-f wrote:Is there a way to get the current instance of WYMeditor?
I've made my own button, which opens a popup window with images user can click on to insert the image. It works.
But in order to get the WYMeditor instance, where to insert the HTML code, I must use
Code: Select all
var wym = window.opener.WYMeditor.INSTANCES[1];

The problem is – I have two instances of WYMeditor on one page, and I don't know which one of them user is currently using.

Is this possible?
I went a couple of times through the jquery.wymeditor.js, but couldn't figure it out by myself.


I think that the easiest way to do this would be to let the window opener function set a "wym" variable in the opened window, witch in turn refers to the local wym instance - i.e. the wym instance that opened the window. But to do this you will need to modify the wym dialogue source.

Here is an example:

Add this line right before the doc.write function call, near the end of the WYMeditor.editor.prototype.dialog function.
Code: Select all
doc.wym = this._wym;


I haven't tested this though, so I won't guarantee anything.
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: Update content with Ajax

Postby akasha on Fri Jan 08, 2010 4:30 pm

Hi,

I have the following code snippet to update a wymeditor instance:
Code: Select all
var editor = $.wymeditors($('.wym_box').index($('#' + response.messagearea).next('.wym_box')));
editor.html(editor.html() + response.template);


if I add editor.html() alerts before and after the editor.html() call above, it seems that (1) I've found the good wymeditor instance, and that its contents gets updated. Still, nothing shows up on my screen. :(

The full code is a bit longer, but here is it in case someone would be interested.
If I disable wymeditor (by uncommenting its initialisation code), then the underlying textarea is updates as it shold.
Code: Select all
var TemplateLoader = {
   init: function(){
      var next = gettext('Next');
      if ($('#jDialog').length != 1) $('body').append('<div id="jDialog"><form></form></div>');
      $('#jDialog').dialog({
         bgiframe: true,
         autoOpen: false,
         height: 300,
         modal: true,
         buttons: {
            next: function() {
               var query = $('#jDialog form').serialize();
               $(this).dialog('close');
               $.getJSON(document.location.pathname + 'template/', query,
                  function(data){
                     TemplateLoader.process_response(data)
                  });
            },
            Cancel: function() {
               $(this).dialog('close');
            }
         },
      })
   },
   load_template: function(template, messagearea) {
      $.getJSON(document.location.pathname + 'template/', {
         'template_name': template,
         'messagearea': messagearea,
         },
         function(data){
         TemplateLoader.process_response(data);
      })
   },
   process_response: function(response) {
      if (typeof(response.template) != 'undefined') {
         if ($('.wym_html_val').length > 0) {
           TemplateLoader.update_wym(response);
        } else {
           $('#' + response.messagearea).val($('#' + response.messagearea).val() + response.template);
        };
         return;
      };
      $('#jDialog form').html(response.input);
      $('#jDialog').dialog('open');
      return;
   },
   update_wym: function(response) {
      var editor = $.wymeditors($('.wym_box').index($('#' + response.messagearea).next('.wym_box')));
      editor.html(editor.html() + response.template);
   },
}

$(document).ready(function(){
   TemplateLoader.init();
   $('.template_button').click(function(event){
    TemplateLoader.load_template($(this).prev('select').val(), $(this).parents('fieldset').find('textarea:first').attr('id'));
    event.preventDefault();
    });
});


could someone point me out the problem?
akasha
 
Posts: 1
Joined: Fri Jan 08, 2010 4:20 pm

Re: Update content with Ajax

Postby mr_lundis on Sat Feb 06, 2010 9:04 pm

If you're getting a valid WYM instance, I don't really see why it doesn't work. If you have several instances on the same page, make sure that the index you receive maps to the currently active or visible instance. If you could provide test page perhaps I can be of more help.

I hope you figure thing out, and I'm sorry about the late reply.

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


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest