Search code examples
asp.net-mvc-4wysihtml5

Issue with the Textarea Readonly when using "wysihtml5" of bootstrap


I have tried to make the text area readonly in MVC4 Application.

But it is always being enable to edit when i use below code:

   @Html.TextAreaFor(model => model.EndUserHelp, new { id = "name1", @class = "editorHelp"})

$('#name1').wysihtml5({
                "font-styles": true,
                "emphasis": true, 
                "lists": true, 
                "html": false, 
                "link": true, 
                "image": true,
                "color": false, 
                "useLineBreaks": true
            });
   $("#name1").prop('readonly', true);

unable to make the area readonly.


Solution

  • You can add the following code where you initialize the editor. I had the same issue with version 0.3.0 and made this to fix it.

    function enforceInactiveStates() {
        var disabled = this.textareaElement.disabled;
        var readonly = !!this.textareaElement.getAttribute('readonly');
    
        if (readonly) {
            this.composer.element.setAttribute('contenteditable', false);
            this.toolbar.commandsDisabled = true;
        }
    
        if (disabled) {
            this.composer.disable();
            this.toolbar.commandsDisabled = true;
        }
    }
    editor.on( 'load', enforceInactiveStates );
    

    Note that 'readonly' is different from 'disabled'.