SJ11
SJ11

Reputation: 101

Limit number of characters allowed in Dojo rich text editor

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

Upvotes: 0

Views: 1078

Answers (2)

vogomatix
vogomatix

Reputation: 5041

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.

Upvotes: 0

Vikram
Vikram

Reputation: 51

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.

Upvotes: 1

Related Questions