문제

Hi I'm using django comments in one of my apps. I customized the comments framework to fit my needs. Everything works properly until I use dojo to make the textarea for the comments expandable http://dojotoolkit.org/reference-guide/1.7/dijit/form/Textarea.html#dijit-form-textarea. After adding the script the form throws an error after submitting: this field is required. So it seems django doesn't recognize the textarea as part of the form anymore.

in my template I use the standart comment tags:

{% render_comment_form for event %}
{% render_comment_list for event %}

When I'm adding the dojo script, the textarea gets expandable, but the form doesn't pass it's value anymore.

dojo.require("dijit.form.Textarea");

dojo.ready(function(){
    var textarea = new dijit.form.Textarea({
        name: "id_comment",
        style: "width:200px;"
    }, "id_comment");
});

dojo adds a bunch of classes to the textarea so that it looks like following. But it still got it's id and it's still a textarea isn't it?

<textarea autocomplete="off" data-dojo-attach-point="focusNode,containerNode,textbox" name="id_comment" class="dijitTextBox dijitTextArea dijitExpandingTextArea" style="overflow-y: hidden; overflow-x: auto; -moz-box-sizing: border-box; width: 200px; height: 36px;" tabindex="0" id="id_comment" widgetid="id_comment" value="" rows="1"></textarea>

After reading the answers for this question: Searching for the Ultimate Resizing Textarea. I thought this might the best way to go but unfortunatly it's not. I'm wondering if it's just me. Is there a way to get this right or should I use a different method to make the field expandable.

Edit

with dojo the post looks like that:

content_type    cylebrations.image
csrfmiddlewaretoken 24827190efbb5b7793aeadaf8276beed
honeypot    
id_comment ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
object_pk   4
post    Post
security_hash   8a091cfbf1e309627369069d4f71c21b33843a85
timestamp   1335209980

without dojo:

comment eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
content_type    cylebrations.image
csrfmiddlewaretoken 24827190efbb5b7793aeadaf8276beed
honeypot    
object_pk   4
post    Post
security_hash   e02d8261f528cfc0f22ee30ced820cfbb80715bc
timestamp   1335210114
도움이 되었습니까?

해결책

Dojo overwrites the name of the textarea. I called it id_comment, instead of just comment. After changing that the post looks just fine and everything works like it should:

    dojo.require("dijit.form.Textarea");

    dojo.ready(function(){
        var textarea = new dijit.form.Textarea({
            name: "comment",
            style: "width:200px;"
    }, "id_comment");
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top