views:

219

answers:

3

Hi, I've been playing around with this for a couple of weeks now with no success...

In a CKEditor dialog, text input fields are renamed with a unique number - e.g. id: 'txtUrl' will become something like id='27_textinput'.

How do I reference this?

// I feel it should be something like:

var myfield = CKEDITOR.instances.myElement.document.$.body.getId('txtUrl');

// or maybe:

var myfield = CKEDITOR.dialog.getContentElement('info','txtUrl');

// and then:

myfield.value = 'myvalue';

But these don't work. Please help! Thanks in advance, R

A: 

get

var ckValue = CKEDITOR.instances['txtUrl'].getData();

and set

CKEDITOR.instances['txtUrl'].setData(ckValue);
great_llama
Hi, thanks for the speedy response! I'm getting "CKEDITOR.instances.txturl is undefined" in FireBug.The instance has the 'name content_main' so I also tried:CKEDITOR.instances.content_main['txt_url'].setData('Hello world');But that throws the same error. An ideas?
A: 

Look at the api dialog sample:

    // Get a reference to the "Link Info" tab.
    var infoTab = dialogDefinition.getContents( 'info' );

    // Set the default value for the URL field.
    var urlField = infoTab.get( 'url' );
    urlField['default'] = 'www.example.com';
AlfonsoML
Hi, sorry I only just saw this!I tried the following under onLoad as per your instructions...var infoTab = dialogDefinition.getContents( 'info' );var urlField = infoTab.get( 'txtUrl' );And then I wanted to set the value onLoad so did the below, but it doesn't work.urlField.setValue = 'www.example.com';Hope you can help!
A: 

Having the same issue i think. Can't figure out how to set dialogDefinition. In the API example to do:

var dialogDefinition = ev.data.definition;

I try to do this in my own code (contents of dialog):

{ type:'select',
            id:'page',
           label:'Pagina:',   
           onChange: function(e){                  
                var dialogDef = e.data.definition;  
                var infoTab = e.getContents( 'info' ); 
            var titleField = infoTab.get( 'titel' );
            titleField['default'] = 'www.example.com';

},     
Rick