hellokuldeep
hellokuldeep

Reputation: 25

Completely disable paste option in CKeditor web page form

I have not been able to disable paste(CTRL+V) option in CKeditor. Although right click paste option is disabled now.

Below is config.js file for CKeditor

CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = 'wordcount,notification';

config.wordcount = {

    // Whether or not you want to show the Paragraphs Count
    showParagraphs: false,

    // Whether or not you want to show the Word Count
    showWordCount: true,

    // Whether or not you want to show the Char Count
    showCharCount: true,

    // Whether or not you want to count Spaces as Chars
    countSpacesAsChars: true,

    // Whether or not to include Html chars in the Char Count
    countHTML: false,

    // Maximum allowed Word Count, -1 is default for unlimited
    maxWordCount: -1,

    // Maximum allowed Char Count, -1 is default for unlimited
    maxCharCount: 2000
};
// The toolbar groups arrangement, optimized for a single toolbar row.
config.toolbarGroups = [
    { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
    { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
    { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
    { name: 'forms' },
    { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
    { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
    { name: 'links' },
    { name: 'insert' },
    { name: 'styles' },
    { name: 'colors' },
    { name: 'tools' },
    { name: 'others' },
    { name: 'about' }
];
CKEDITOR.config.toolbar = [
   ['Format','FontSize'],

   ['Bold','Italic','Underline','StrikeThrough','-','Undo','Redo','-','Cut','Copy','Paste','Find','Replace','-','Outdent','Indent','-','Print'],

   ['NumberedList','BulletedList','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
   ['-','Link']
] ;
// The default plugins included in the basic setup define some buttons that
// are not needed in a basic editor. They are removed here.
config.removeButtons = 'Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript';

// Dialog windows are also simplified.
config.removeDialogTabs = 'link:advanced';

};

This is how the editor looks like

Controller function loading this editor is-

public function edit_cv(){
$user_id= $this->CI->session->userdata('id');
$this->addJS("tnpcell/edit.js");
$this->addJS("ckeditor/ckeditor.js");
$this->addJS("ckeditor/samples/js/sample.js");
$data['cv_data'] = $this->cv_model->get_achievements($user_id);
foreach ($data['cv_data'] as $row){
      $row->editor_content = urldecode($row->editor_content);
      $row->skype_id = urldecode($row->skype_id);
      $row->shoe_size = urldecode($row->shoe_size);
      $row->blood_group = urldecode($row->blood_group);
      $row->specialization = urldecode($row->specialization);
      $row->editor_content = str_replace('$.ol.$', '<ol>', $row->editor_content);
      $row->editor_content = str_replace('$.ul.$', '<ul>', $row->editor_content);
      $row->editor_content = str_replace('$.li.$', '<li>', $row->editor_content);
      $row->editor_content = str_replace('$./ol.$', '</ol>', $row->editor_content);
      $row->editor_content = str_replace('$./ul.$', '</ul>', $row->editor_content);
      $row->editor_content = str_replace('$./li.$', '</li>', $row->editor_content);
      $row->editor_content = str_replace('$.nbsp.$', '&nbsp;', $row->editor_content);
}
$data['project_data'] = $this->cv_model->get_project($user_id);
foreach ($data['project_data'] as $row) {
      $row->title = urldecode($row->title);
      $row->role = urldecode($row->role);
}
$this->load->model('course_structure/basic_model','',TRUE);
$this->load->model('student/student_academic_model','',TRUE);
$data['student_academic']=$this->student_academic_model->get_stu_academic_details_by_id($user_id);
$data['branch_name']=$this->basic_model->get_branch_details_by_id($data['student_academic']->branch_id)[0]->name;

$this->drawHeader("Edit Your CV");
$this->load->view('tnpcell/edit_cv',$data);
$this->drawFooter();

}

I want user should not be able to paste any text in the field of editor (as shown in picture above). But currently pasting some text using ctrl+V is enabled.

Upvotes: 0

Views: 4500

Answers (1)

Wizard
Wizard

Reputation: 3151

You can cancel the paste event.

CKEDITOR.instances.editor1.on('paste', function(evt) {
    evt.cancel();
});

Upvotes: 4

Related Questions