⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


Insert <div> in CRUD form


  • Please log in to reply
5 replies to this topic

#1 RSPeres

RSPeres

    Member

  • Members
  • PipPip
  • 12 posts

Posted 13 December 2012 - 11:51 AM

Hi,

I have a ajax tree menu to let my user choose a file from a folder. This file needs to be inserted in database with another options. Any Ideas in how I put the javascript tree menu in the add/edit form?? My fields in the form are: Name, Size, file (the tree to select the file)...

Thank's in advance

#2 dontako

dontako

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts

Posted 13 December 2012 - 01:16 PM

Hi! You can use callbacks before add and edit.

...
$crud->fields('Name','Size','myFileSelected');

$crud->callback_add_field('myFileSelected', array($this, 'myTree'));
$crud->callback_edit_field('myFileSelected', array($this, 'myTree'));

...

//Callback
function myTree()
{
...
$var = code for Show Your Tree
....
//We'll add the value later
$var .= '<input type="hidden" name="treeFileSelected" id="treeFileSelected" value="" />';

return $var
}

And in your view add The Tree Javascript (If any), at bottom.
and When the user select any element of your tree, simply change the Value of your hidden input created at callback

function on click element()
{
$('#treeFileSelected').val('YOUR NAME OR ID OF SELECTED FILE');
}

Remember Set Rules for this hidden input..

Hope it Helps :)

Sry My English xD
I dont test my code, so could have errors, but its an idea..

#3 RSPeres

RSPeres

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 December 2012 - 07:22 PM

Hi! You can use callbacks before add and edit.

...
$crud->fields('Name','Size','myFileSelected');

$crud->callback_add_field('myFileSelected', array($this, 'myTree'));
$crud->callback_edit_field('myFileSelected', array($this, 'myTree'));

...

//Callback
function myTree()
{
...
$var = code for Show Your Tree
....
//We'll add the value later
$var .= '<input type="hidden" name="treeFileSelected" id="treeFileSelected" value="" />';

return $var
}

And in your view add The Tree Javascript (If any), at bottom.
and When the user select any element of your tree, simply change the Value of your hidden input created at callback

function on click element()
{
$('#treeFileSelected').val('YOUR NAME OR ID OF SELECTED FILE');
}

Remember Set Rules for this hidden input..

Hope it Helps :)

Sry My English xD
I dont test my code, so could have errors, but its an idea..



Hi Dontako,

Very good solution. Just a newbie question. Since my tree has a lot of html and javascript, there's a way to include this file in your solution, intead putting all this html inside a PHP var?
Something like load a view...

thank's again

#4 dontako

dontako

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts

Posted 14 December 2012 - 07:46 PM

MMMM I think you can do the following trick, would not be the best option perhaps another user can tell something more efficient.

(Note: I personally do not like to use file_get_contents, but if you load a view with $ this-> load-> view ('name'), it will be above all the HTML code ...)
well, you can do this:

//Callback
function myTree()
{
$var = file_get_contents(base_url('assets/all.html')); //File with all script and HTML
//We'll add the value later
$var .= '<input type="hidden" name="treeFileSelected" id="treeFileSelected" value="" />';

return $var
}

NOTE: allow_url_fopen MUST be activated

Regards

#5 RSPeres

RSPeres

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 December 2012 - 09:48 PM

Solved! I don't know if it's the best way but...



$crud->callback_add_field('myFileSelected', array($this, 'myTree'));
$crud->callback_edit_field('myFileSelected', array($this, 'myTree'));


function myTree(){
return $this->load->view('treeView', array(), true);
}

Where treeView.php is a html file with javascript.

Thank's for the help dontako

#6 dontako

dontako

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts

Posted 17 December 2012 - 01:33 PM

Your Welcome ;3




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users