CKEditor and ASP.Net MVC 3 RequiredAttribute

前端 未结 7 617
情深已故
情深已故 2020-12-08 15:56

I\'ve integrated CKEditor 3 (formerly FCKEditor) into my asp.net MVC (v3 to be specific) application. I have a RequiredAttribute in my model for the field that needs the edi

7条回答
  •  心在旅途
    2020-12-08 16:10

    Thanks for the answers. Thanks to this post I've found my own solution which suits my case perfectly.

    If you don't want to use click/mousedown event, but instead, want to trigger the validation on the right form-submit event you can use the following approach.

    It doesn't use neither jQuery-Adapter CKEditor plugin nor click event. And it's possible to apply it to all forms with ckeditor.

    $('form').on('submit.ckeditorValidation', function () {
        var $this = $(this);
        var $ckeditor = $this.find('textarea.ckeditor');
    
        // if no ckeditor for this form then do nothing
        if (!$ckeditor || !$ckeditor.length) {
            return true;
        }
    
        // update content from CKEditor to TextArea
        var textAreaId = $ckeditor.attr('id');
        CKEDITOR.instances[textAreaId].updateElement();
    
        // trigger validation and check if the form is valid
        if (!$this.valid()) {
            return false;
        }
    
        // if form is valid then
        // unsubscribe current event handler to avoid endless recursion
        // and re-trigger form submit
        $(this).off('submit.ckeditorValidation').submit();
        return true;
    });
    

提交回复
热议问题