2011-05-20 41 views
3

没有人有知道如何提交包含Dojo富文本编辑器的形式?表单提交了Dojo富文本编辑器

我试着加入“名”属性来我的元素装饰着的dojoType =“dijit.Editor”,但是,我没有看到任何的HTML我的接收过程。

我检查的文件,我没有看到任何明显的例子(比随的“值”设置了一个隐藏输入的数据的另一个功能连接形式的对提交事件在其他问题富文本编辑器“)。

我会假设必须有一些‘容易’的方式来做到这一点?

回答

3

这里IM能值发送到服务器,并且能够在提交的值重新显示为编辑器的初始显示值。

<html> 
<head> 
<style type="text/css"> 
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css"; 
</style>   
<script src="djlib/dojo/dojo.js" type="text/javascript" djConfig="parseOnLoad:true"></script> 
<link rel="stylesheet" href="djlib/dojox/grid/resources/Grid.css" type="text/css" /> 
<body class="claro"> 
    <?php if(count($_POST) > 0) { 
      echo '<script>function dumpSubmittedEditorValue(){}</script>'; 
      echo "<script>var submittedEditorValue = '$_POST[ed1]'</script> "; 
     } 
    ?> 
    <form jsId="frm1" dojoType="dijit.form.Form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
     <input type="hidden" name="ed1" /> 
     <span dojoType="dijit.form.Button"> 
      Submit 
      <script type="dojo/method" event="onClick"> 
       frm1.submit(); 
      </script> 
     </span> 
    </form> 
    <div dojoType="dijit.Editor" id="editor1">   
     <script type="dojo/method"> 
      this.hiddenField = dojo.query("[name=ed1]")[0]; 
      //console.log(this.hiddenField); 
      /*dojo.connect(this.document.body,'onload',function(){     
       console.log("A"); 
       console.log(this.document.body); 
      })*/ 
     </script> 
     <script type="dojo/method" event="onChange" args="val"> 
      //1st format. <p>  hi - should be - <p>HI 
      var str = dojo.string.trim(val); 

      var tagsEncoded = dojox.html.entities.encode(str, encodecustomMap); 
      var whiteSpaceEncoded= tagsEncoded.replace(/\s/ig,"%20"); 
      this.hiddenField.value = whiteSpaceEncoded; 
      console.log(this.hiddenField.value) 
      //console.log(dojox.html.entities.decode(whiteSpaceEncoded.replace(/%20/ig," "), decodecustomMap)) 


     </script> 


    </div> 
    <script> 
     var decodecustomMap = [     
       ["\u003C", "lt"], 
       ["\u003E", "gt"], 
       ["\u0026", "amp"] 
      ]; 
      var encodecustomMap = [ 
       ["\u003C", "lt"], 
       ["\u003E", "gt"] 
      ]; 
    </script> 
</body> 

<script>  
    dojo.require("dijit.Editor"); 
    dojo.require("dojox.html.entities"); 
    dojo.require("dijit.form.Form"); 

    dojo.addOnLoad(function(){ 
     console.log(dojo.query("iframe", dijit.byId("editor1").domNode)) 
     dojo.connect(dojo.query("iframe", dijit.byId("editor1").domNode)[0],'onload',function(){ 
      console.log(this.contentDocument.body) 
      this.contentDocument.body.innerHTML = getEditorIntialValue(); 
     }) 
     function getEditorIntialValue(){ 
      if(typeof submittedEditorValue != "undefined"){ 
       submittedEditorValue = dojox.html.entities.decode(submittedEditorValue,decodecustomMap); 
       submittedEditorValue = submittedEditorValue.replace(/%20/ig,"&nbsp;"); 
       return submittedEditorValue; 
       //dijit.byId("editor1").document.body.innerHTML = submittedEditorValue; 
      } 
      else{ 
       return ""; 
      } 
     } 

    }) 
</script> 
</html> 
+0

我明白你在做什么摹这里...聪明......但是,这是一种同样作为听众的onsubmit连接到一个形式,抓住什么是在RTE的。感谢您的回复......我将其标记为已回答。 – 2011-05-24 17:08:10

+0

我认为RTE不具有与其相关联存储编辑文本的隐藏字段,用户键入。所以我认为这可能是其中一种方式。纠正我,如果我错了 – rajkamal 2011-05-25 05:36:52

+0

不好...这很好。我以不同但类似的方式实现了它。我做了我的形式的“提交”事件dojo.connect和有线一个二级处理抢值超出我的RTE的,把它扔进一个隐藏的文本框中。 – 2011-05-25 11:50:04