ItayXD
ItayXD

Reputation: 48

input value won't update

Ok, I've been trying to get this script to work but I just can't figure out what's wrong. I'm trying to get tinyMCE to take input from 2 fields using jquery dialogue and output it in specific format. Here is my tinyMCE plugin code:

(function() {
tinymce.create('tinymce.plugins.RMFtooltip', {
    init : function(ed, url) {
        ed.addButton('RMFtooltip', {
            title : 'ToolTip',
            image : url+'/RMFtooltipbutton.png',
            onclick : function() {
                i = jQuery('<div title="Create your tooltip" ></div>');
               /*jQuery.get(url+'/ajax/form.html', function(data) {
                  i.html(data);
                });*/
                i.load(url+'/ajax/form.html');
                i.dialog({
                    autoOpen: true,
                    draggable: false,
                    resizable: false,
                    modal: true,
                    buttons: {
                        "OK": function() {
                            RMFtooltip_text = jQuery("#RMFtooltip_text").val();
                            RMFtooltip_tip = jQuery("#RMFtooltip_tip").val();
                            if (RMFtooltip_text != null && RMFtooltip_text != '' && RMFtooltip_tip != null && RMFtooltip_tip != ''){
                                ed.execCommand('mceInsertContent', false, '[tooltip tip="'+RMFtooltip_tip+'"]'+RMFtooltip_text+'[/tooltip]');
                            }
                            jQuery( this ).dialog( "close" );
                        },
                        Cancel: function() {
                            jQuery( this ).dialog( "destroy" );
                        }
                    }
                });
...

Now, the first time I click the button in tinyMCE everything works fine, but if I click it again I get the same out put no matter what the input is. eg: I enter foo in the text and bar in the tip and click ok, everything works fine (I get "[tooltip tip="bar"]foo[/tooltip]"), then I use it again, this time I enter blah in the text and blue in the tip, but I still get the same output ("[tooltip tip="bar"]foo[/tooltip]"). It seems that it doesn't re read the input... Please help


PS: I'm using ajax to get the form (because this is a js file), I can attach it here but it doesn't seems like it could matter to me....

Upvotes: 2

Views: 573

Answers (1)

Nate
Nate

Reputation: 661

You will need to empty the dialog each time you close it as jQuery will just keep creating new html behind the scenes each time your click function is called. You will never see this html again, but it's there and is messing with your calls using the IDs of your form elements.

To fix this, just empty the dialog after each call

//...
buttons: {
        "OK": function() {
            RMFtooltip_text = jQuery("#RMFtooltip_text").val();
            RMFtooltip_tip = jQuery("#RMFtooltip_tip").val();
            if (RMFtooltip_text != null && RMFtooltip_text != '' && RMFtooltip_tip != null && RMFtooltip_tip != ''){
                ed.execCommand('mceInsertContent', false, '[tooltip tip="'+RMFtooltip_tip+'"]'+RMFtooltip_text+'[/tooltip]');
            }
            jQuery( this ).dialog( "close" );
            jQuery(this).empty(); //Add this

        },
            Cancel: function() {
                jQuery( this ).dialog( "destroy" );
                jQuery(this).empty(); //Add this
            }
    }
//...

Upvotes: 2

Related Questions