⚠ 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

Insert <div> in CRUD form



RSPeres
  • profile picture
  • Member

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

dontako
  • profile picture
  • Member

Posted 13 December 2012 - 13: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..

RSPeres
  • profile picture
  • Member

Posted 14 December 2012 - 19:22 PM

[quote name='dontako' timestamp='1355404571' post='4698']
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..
[/quote]


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

dontako
  • profile picture
  • Member

Posted 14 December 2012 - 19:46 PM

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

(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
}


[i]NOTE: allow_url_fopen MUST be activated[/i]

Regards

RSPeres
  • profile picture
  • Member

Posted 14 December 2012 - 21:48 PM

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



[color=#000000]$crud[/color][color=#666600]->[/color][color=#000000]callback_add_field[/color][color=#666600]([/color][color=#008800]'myFileSelected'[/color][color=#666600],[/color][color=#000000] array[/color][color=#666600]([/color][color=#000000]$this[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'myTree'[/color][color=#666600]));[/color]
[color=#000000]$crud[/color][color=#666600]->[/color][color=#000000]callback_edit_field[/color][color=#666600]([/color][color=#008800]'myFileSelected'[/color][color=#666600],[/color][color=#000000] array[/color][color=#666600]([/color][color=#000000]$this[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'myTree'[/color][color=#666600]));[/color]


[font=Monaco][size=2][color=#920068]function [/color]myTree(){[/size][/font]
[font=Monaco][size=2][color=#920068]return [/color]$this->[color=#2c00c9]load[/color]->view([color=#2c00c9]'treeView'[/color], [color=#920068]array[/color](), [color=#920068]true[/color]);[/size][/font]
[font=Monaco][size=2]}[/size][/font]

Where treeView.php is a html file with javascript.

Thank's for the help dontako

dontako
  • profile picture
  • Member

Posted 17 December 2012 - 13:33 PM

Your Welcome ;3