⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callbacks on textarea breaks TinyMCE



cboyd
  • profile picture
  • Member

Posted 30 April 2012 - 15:29 PM

I am attempting to add two callbacks on a textarea which I want to have the WYSIWYG editor. So I have done:

$crud->callback_add_field('copy',array($this,'set_copy_textarea'));
$crud->callback_edit_field('copy',array($this,'set_copy_textarea'));

with the following function:

function set_copy_textarea($value, $primary_key)
{
return '<textarea name="copy" class="texteditor">'.$value.'</textarea>';
}

The function runs and creates the textarea correctly, however, the TinyMCE functionality is lost. If I remove the two callbacks, the textarea renders correctly. Any solutions for this?

Thanks!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 30 April 2012 - 18:19 PM

You can try to add these lines of code:


$crud->set_js('assets/grocery_crud/texteditor/jquery.tinymce.js');
$crud->set_js('assets/grocery_crud/js/jquery_plugins/config/jquery.tine_mce.config.js');

cboyd
  • profile picture
  • Member

Posted 30 April 2012 - 22:10 PM

Thanks, web-johnny, but the javascript files are already included. As I said, if I eliminate the callback functions, the WYSIWYG renders as it should.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 30 April 2012 - 23:58 PM

Yes I know, but when you call the callback the default functionality of the texteditor doesn't triggered so you need to add the javascript like this

cboyd
  • profile picture
  • Member

Posted 01 May 2012 - 12:19 PM

Thanks again, web-johnny, but that didn't help. Any other thoughts?

I am having a similar issue when trying to add a callback event to a related field. I lose the nulti-select ability (but that may be a seperate issue).

Thanks for your help!

alhuzn
  • profile picture
  • Member

Posted 01 May 2012 - 14:59 PM

[quote name='web-johnny' timestamp='1335809962' post='1549']
You can try to add these lines of code:


$crud->set_js('assets/grocery_crud/texteditor/jquery.tinymce.js');
$crud->set_js('assets/grocery_crud/js/jquery_plugins/config/jquery.tine_mce.config.js');

[/quote]

as default, [b]jquery-[version].min.js[/b] is writen after the two js above, so the tinymce can't rendered. the solution is to add the following line, ABOVE (remember, above) the two lines mentioned.


$crud->set_js('assets/grocery_crud/js/jquery-[version].min.js');


replace [b][version][/b] with the version of your jquery.

please forgive my english :(

alhuzn
  • profile picture
  • Member

Posted 01 May 2012 - 15:02 PM

or just add the following line to solve everything ...


$crud->change_field_type('copy','text');


hope that helps ...

cboyd
  • profile picture
  • Member

Posted 01 May 2012 - 16:03 PM

Thanks alhuzn (and web-johnny)! Adding the jQuery script link resolved my issue.

alhuzn
  • profile picture
  • Member

Posted 01 May 2012 - 16:11 PM

[quote name='cboyd' timestamp='1335888227' post='1565']
Thanks alhuzn (and web-johnny)! Adding the jQuery script link resolved my issue.
[/quote]

enjoy

David
  • profile picture
  • Member

Posted 23 August 2013 - 17:33 PM

Hi, all

I am having a similar issue when trying to add a callback event for defualt value.

i see head tag and find jquery main file load after tinymce when i use set_js.

All solution won't work for me, please help me


davidoster
  • profile picture
  • Member

Posted 23 August 2013 - 22:55 PM

Hello and welcome to the forums [member=david].

Please share your controller's function.


David
  • profile picture
  • Member

Posted 24 August 2013 - 04:59 AM

Here you are : 

I want --- text feild ---- have defualt value

public function index()
    {
        $crud = new grocery_CRUD();
        $crud->set_theme('flexigrid');
        $crud->set_table('news');
        $crud->columns('nid', 'title','cat', 'publish_time');
        $crud->display_as('nid','شماره خبر');
        $crud->display_as('on_title','رو تیتر');
        $crud->display_as('title','تیتر');
        $crud->display_as('led','لید');
        $crud->display_as('text','متن');
        $crud->display_as('img','تصویر');
        $crud->display_as('small_pic','تصویر کوچک');
        $crud->display_as('our_news','تولیدی');
        $crud->display_as('our_suggest','پیشنهاد ما');
        $crud->display_as('cat','بخش');
        $crud->display_as('chosed','برگزیده');
        $crud->display_as('film','فیلم');
        $crud->display_as('sound','صوت');
        $crud->display_as('pic','تصویر');
        $crud->display_as('karikator','کاریکاتور');
        $crud->display_as('dy','سال انتشار');
        $crud->display_as('dm','ماه انتشار');
        $crud->display_as('dd','روز انتشار');
        $crud->display_as('dh','ساعت انتشار');
        $crud->display_as('dmin','دقیقه انتشار');
        //$crud->display_as('add_time','زمان اضافه شدن');
        $crud->display_as('publish_time','زمان انتشار');
        $crud->display_as('is_published','منتشر شده؟');
        $crud->display_as('blog_id','وبلاگ');
        $crud->display_as('news_agency','سیستم خبری');
        $crud->display_as('etm','ماه انقضا');
        $crud->display_as('book','کتاب');
        $crud->display_as('cinema','سینما');
        $crud->display_as('keywords','تگ ها');
        $crud->display_as('views','تعداد نمایش');
        $crud->display_as('slide_show','اسلاید شو');
        $crud->display_as('multimedia','چند رسانه ای');
        
        $crud->field_type('publish_time', 'hidden');
        $crud->field_type('add_time', 'hidden', time());
        
        $crud->set_field_upload('img','assets/uploads');
        $crud->set_field_upload('small_pic','assets/uploads');
        $crud->set_field_upload('multimedia','assets/uploads');
        
        $crud->set_relation('cat','cats','cat_real_name');
        $crud->set_relation('blog_id','blogs','{name} - {address}');
        $crud->set_relation('news_agency','newsagency','name');
        
        $crud->callback_column('publish_time',array($this,'_make_real_date'));
        $crud->unset_texteditor('led','keywords');
        $crud->order_by('nid','desc');
        $crud->required_fields('is_published','cat','our_news','title','text');
        $crud->add_fields('on_title','title','led','text','keywords','img','small_pic','cat','multimedia','blog_id','news_agency','dy','dm','dd','dh','dmin','add_time','publish_time','is_published','our_news','etm','chosed','film','sound','pic','karikator','slide_show','book','cinema');
        $crud->edit_fields('on_title','title','led','text','keywords','img','small_pic','cat','multimedia','blog_id','news_agency','dy','dm','dd','dh','dmin','publish_time','is_published','our_news','etm','chosed','film','sound','pic','karikator','slide_show','book','cinema');
        
        $crud->callback_before_insert(array($this,'savePublishTime'));
        $crud->callback_before_update(array($this, 'savePublishTime'));
        
        $crud->callback_after_insert(array($this, 'clear_cache'));
        $crud->callback_after_update(array($this, 'clear_cache'));
        $crud->callback_after_delete(array($this,'clear_cache'));
   
        $output = $crud->render();
        $this->load->view('admin/news/index',$output);
    }

davidoster
  • profile picture
  • Member

Posted 24 August 2013 - 06:46 AM

Hello again David.

first of all I would suggest to move this code to another function because there are some known issues when running Grocery CRUD code from the index function.

 

// on your controller's function what ever you name it, e.g. news add

$crud->callback_field('text', array($this, 'cb_text_field');

 

// then on your controller add the callback function (or whatever you want to call it)

function cb_text_field($value, $primary_key = null)

{

 $value = ''; // here put your default value as a static value or you can get it from the database

 return '<input type="text" maxlength="50" value="'.$value.'" name="text" style="width:462px">';

}


David
  • profile picture
  • Member

Posted 24 August 2013 - 15:37 PM

I'm so sorry David  :wub:

i want to add default value to textarea and i want to tinymce work with theme.