two different editors

two different editors

thomas-99thomas-99 Posts: 7Questions: 1Answers: 0

Hi
from the server I get a config that should show two different editors templates. Depending on the config another template is

displayed.function template1() {
var html = <div id="customForm1"> <fieldset class="firma"> ..... </fieldset> </div>
$("#templates").html("");
$("#templates").append(html);
editor.template('#customForm1');
}

displayed.function template2() {
var html = <div id="customForm2"> <fieldset class="name"> ..... </fieldset> </div>
$("#templates").html("");
$("#templates").append(html);
editor.template('#customForm2');
}

editor.on( 'open', function ( e, o, action) {
var firma = this.field( 'firma' );
if (firma.val().length > 0){
template1()
} else {
template2()
}

It does not work like that. Can not I assign an HTML template at runtime?
How would I have to change that to work correctly?

THANK YOU
Ciao

Replies

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    You can, but its too late by the time the open is called. Use preOpen.

    Allan

  • thomas-99thomas-99 Posts: 7Questions: 1Answers: 0

    That just does not want to work. The template is not displayed with Open or preOpen.

    var html1 = '<div id="templates1"><fieldset class="name"><legend>html1</legend>....' 
    var html2 = '<div id="templates2"><fieldset class="name"><legend>html2</legend>....'
    
    editor.on( 'preOpen', function ( e, o, action) {
    var test = this.field( 'firma' );
    if (cm.val().length > 0){
     editor.template(html1);
             }else {
     editor.template(html2);
     }
     }
    
  • thomas-99thomas-99 Posts: 7Questions: 1Answers: 0

    The template is displayed in the editor. It takes two clicks. The first click displays the wrong template. Another click then displays the correct template. Does the old template have to be deleted? Will not this be overwritten? Or does it have to be reinitialized?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Sorry! I'd completely lost track of this thread!

    Looking at the code sequence a bit closer preOpen is actually too late for the template as well. However, what we can do is trigger a forced redraw of the new template through use of the order() method:

    var html1 =
      '<div id="templates1"><fieldset class="name"><legend>html1</legend>....';
    var html2 =
      '<div id="templates2"><fieldset class="name"><legend>html2</legend>....';
    
    editor.on("preOpen", function(e, o, action) {
      var test = this.field("firma");
      if (cm.val().length > 0) {
        editor.template(html1);
      } else {
        editor.template(html2);
      }
      editor.order( editor.order() );
    });
    

    Its a little bit of a hack and I feel there should probably be a better way to do this, but that way will work in the current release.

    Allan

This discussion has been closed.