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

Error when using .insert()?

Support forum for WYMeditor.

Error when using .insert()?

Postby Lashiec on Thu Oct 23, 2008 3:38 pm

I get this error:

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://127.0.0.1/Classes/Email/scripts/ ... or.pack.js :: anonymous :: line 1" data: no]

What I'm doing is this:

I have a drop down box, so when someone selects an item from the list it inputs a message in the WYM box (grabs from a database). It works fine, but if I type anything in the WYM box and try the drop down menu, it does that.

This is my code... It also seems to add an extra <p></p> in the display window of the WYM box, but it doesn't actually show up in the HTML for the WYM box. I also think the line that shows wym.html(''); could be wrong. I wanted to clear the box before it does the .insert(data)

Code: Select all
$(document).ready(function() {
         jQuery(function() {
            jQuery('.wymeditor').wymeditor({
               postInit: function(wym){
                 $('#template_box').bind('change', function(e){
                     $num = $('#template_box').val();
                     $.post('admin/ajax.php?action=get_template', {id: $num},
                        function(data) {
                           wym.html('');
                           wym.insert(data);
                        })
                  })
               }
            });
         });
      })
Lashiec
 
Posts: 3
Joined: Thu Oct 23, 2008 3:33 pm

Re: Error when using .insert()?

Postby mr_lundis on Tue Oct 28, 2008 5:04 pm

Hello!

Do you think that you could set up some kind of test page for us? It would make helping you it a lot easier!

Cheers! :wink:
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: Error when using .insert()?

Postby Lashiec on Sun Nov 02, 2008 12:04 am

Yeah, no problem. When I get back to work on Monday I'll set the page up on our server and post a link here. Thanks!
Lashiec
 
Posts: 3
Joined: Thu Oct 23, 2008 3:33 pm

Re: Error when using .insert()?

Postby Lashiec on Mon Nov 03, 2008 2:09 pm

http://24.230.153.90/Email/template.php

That's the page that throws the error. If you pick an item from the drop down menu it puts text in the wymeditor, it also inserts an extra <p> line, which doesn't appear in the HTML. Also, if you type in the wymeditor box and then switch the drop down menu it throws out that error.

It's doing an ajax call to another page that outputs the html when you switch the drop down menu. It then takes the returned html and inserts it.
Lashiec
 
Posts: 3
Joined: Thu Oct 23, 2008 3:33 pm

Re: Error when using .insert()?

Postby mr_lundis on Mon Nov 03, 2008 7:09 pm

Okay, now I've taken a look at you page...

The error you get is because you try to insert code into a selection that doesn't exist (as the editor has been emptied), this is also why you get that extra paragraph, as the insert method falls back to the paste method when there's no selection. However, when you click inside the editor, you crate a new selection, but the html elements that is refers to gets erased when you call the html method, thus the error, as the selection still exist when insert is called.

If you do it like this instead you will go around all these problems, it's also a more efficient way of doing things.
Code: Select all
$(document).ready(function() {
         jQuery(function() {
            jQuery('.wymeditor').wymeditor({
               postInit: function(wym){
                 $('#template_box').bind('change', function(e){
                     $num = $('#template_box').val();
                     $.post('admin/ajax.php?action=get_template', {id: $num},
                        function(data) {
                           wym.html(data);
                        })
                  })
               }
            });
         });
      })


As you see, the html method takes any string as an argument, and it will replace the editor content with the string provided.

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 5 guests

cron