⚠ 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

New custom field with text editor



superdan

superdan
  • profile picture
  • Member

Posted 17 December 2015 - 08:51 AM

Hi all,

i would like to add a custom field to my page ( i would like to use a callbak function ).
This custom field MUST be a text-editor field.
I would like to insert in it a text from another table field  text when im in editing mode and then update the text into the another table field when i save.
The problem is - for the momet - that im not able to add a custom text editor field ( im only able to make it a textarea field ).

e.g. of my code:

$this->grocery_crud->callback_edit_field('note',array($this,'callback_my_field'));
$this->grocery_crud->->change_field_type('note', 'text');

but nothing happened, it appears only as a normal input field or a textarea field if i set it as a textarea

BUT NOT at all as text editor field.

Second question.

with a callback, how can i insert a defalut text value in this form-text-area ( from a mysql query )?

Thanks you so much!


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 17 December 2015 - 23:32 PM

A callback function is something you can always rely on when u wana have customized input fields .. you may emit the same field structure like GC builds with the value attribute used to fill in the default value for input ... or whatever type you use - its the same way had u done it in core php..

 

But if you looking to have default values in add form - there are some solutions shared across forum - you can hunt for the same and you will be able to get what you actually trying to achieve.

 

happy GCing :)


superdan

superdan
  • profile picture
  • Member

Posted 18 December 2015 - 16:55 PM

Hi Amit,

thank for your andswer but i still cant fin a way to set a custo field as a text-editor field.

I can set all field type but im not able to show it with the default text-editor of GC.

Have you some hint?
Thanks


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 18 December 2015 - 23:23 PM

So I think problem is next - u wanna set custom textfield with texteditor,

but u dont have any other fields with type 'text', so GC doesnt add to the page  js for texteditor plugin like ckeditor(or tinymce)

Solution: if dont have another fields with type 'text' u need add  js by manualy.

Example:

Somewhere in current controller or better in MY_Controller, then u could use this in any controller, set method
 

//this js you should output somewhere on the page after JQuery 
public js_files = arrray();



protected function load_texteditor()
{
    $default_texteditor_path = 'assets/grocery_crud/texteditor';
    $this->js_files[] = $default_texteditor_path.'/ckeditor/ckeditor.js';
    $this->js_files[] = $default_texteditor_path.'/ckeditor/adapters/jquery.js';        
}

//then in current controller u call
$this->load->texteditor();


Custom callback field
 

public function _custom_textfield_with_text_editor($val, $id=NULL)
{
    $value_from_another_table = '';

    //query to database and get value per $id if u need it
    $data_from_db = ...query;

    if($data_from_db) $value_from_another_table = $data_from_db;
                      //custom field name,    //value          //class for texteditor            
    return form_textarea('message', $value_from_another_table,'class="texteditor"');       
      
}

Be careful -  add js only when u dont have other fields with type 'text', otherwise u just use only callback function

This is my solution, mb u find more better :)
 

like Amit say - happy GCing


superdan

superdan
  • profile picture
  • Member

Posted 23 December 2015 - 08:21 AM

EPIC WIN!
Thank you so much Paul!!!!!!