【问题标题】:Submitting a form with a Dojo Rich Text Editor使用 Dojo 富文本编辑器提交表单
【发布时间】:2011-08-29 18:00:44
【问题描述】:

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

我尝试将“name”属性添加到用 dojoType="dijit.Editor" 装饰的元素中,但是,我在接收过程中看不到任何 HTML。

我检查了文档,但没有看到任何明确的示例(除了将相关表单的 on submit 事件与另一个函数连接起来,该函数将隐藏输入的数据设置为 Rich 的“值”文本编辑器”)。

我认为必须有一些“更简单”的方法来做到这一点?

【问题讨论】:

    标签: forms richtextbox dojo rich-text-editor


    【解决方案1】:

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

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

    【讨论】:

    • 我明白你在做什么......聪明......但是,这有点像将 onSubmit 监听器附加到表单并抓取 RTE 中的内容。感谢您的回复...我会将其标记为已回答。
    • 我认为 RTE 没有与之关联的任何隐藏字段来存储用户输入的编辑器文本。所以我认为这可能是其中一种方式。如果我错了,请纠正我
    • 不...很好。我以不同但相似的方式实现了它。我在表单的“提交”事件上做了一个 dojo.connect,并连接了一个辅助处理程序以从我的 RTE 中获取值并将其放入隐藏的文本框中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多