开发者

Limit number of characters allowed in Dojo rich text editor

Is there any way to 开发者_JAVA百科limit the number of characters in DOJO rich text editor? I googled and tried to search the API but couldn't find any reference.


I dont think there is a direct way to limit the no of characters in dojo editor (not sure though someone can put more insights on the same). You need to make use of javascript to capture the events like onChange() or onKeyDown() etc (refer Dojo API) and handle the same in the javascript.If there is a better solution please do let me know.


There are other online references which suggest that hooking up to onkeyup is the best bet... You can possibly create a derived dijit.ValidEditor which has an isValid check for the character limit or monitor the length

<script>
    dojo.require("dijit.Editor");
    dojo.addOnLoad(function() {
        var valid = true;
        var maxLimit = 1000;
        var editor = dijit.byId("myEditor");
        dojo.connect(editor, "onKeyUp", this, function(event) {
            valid = (editor.get("value").length) > maxLimit) ? false : true;
        });
    });
</script>

N.B. This is not my code and it is older style Dojo - I've just put it here to make the outline solution complete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜