⚠ 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

add_fields and callback_add_field design problem



cesaret_2000
  • profile picture
  • Member

Posted 07 March 2012 - 11:01 AM

I have a weird design problem when I use add_fields and callback_add_field at the same time.

I need to see different fields when I'm in add or in edit, so I have

$crud->add_fields('my_id');

Also, to choose "my_id" I have a custom select, so I have

$crud->callback_add_field('my_id', array($this, 'my_select'));
$crud->callback_edit_field('my_id', array($this, 'my_select'));

And my callback function, to test

function my_select($value)
{
$input = "<select name='my_id' id='' class='chosen-select' data-placeholder='Select ...'>";
$input .= "<option value=''></option>";
$input .= "<option value=''>Hello</option>";
$input .= "</select>";
return $input;
}

In edit everything is ok

[attachment=62:2012-03-07_115503.jpg]

But see what happens in add

[attachment=63:2012-03-07_115552.jpg]

If I don't use the $crud->add_fields('my_id'); everything is all right.

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

Posted 07 March 2012 - 18:55 PM

This is because you have a javascript error. It is probably a PHP error that causes also a Javascript error . So simply try this one:


function my_select($value = null) //The only change I did is this line
{
$input = "<select name='my_id' id='' class='chosen-select' data-placeholder='Select ...'>";
$input .= "<option value=''></option>";
$input .= "<option value=''>Hello</option>";
$input .= "</select>";
return $input;
}


and probably it will work. At the callback_add_field I don't pass any parameter so it cause for sure an error there that the parameter is not found.

P.S. Really thank you to give so good example for your problem. Perfect description . You have all the code that causes the problem and not for example all the controller and a print-screen ;)

cesaret_2000
  • profile picture
  • Member

Posted 08 March 2012 - 09:47 AM

Thanks so much for your help. Unfortunately, your solution is not working either, anyway I changed it. This has not sense, I explain you why...

If I have only the function
$crud->callback_add_field('my_id', array($this, 'my_select'))

with, of course, the function definition
function my_select($value = null)...

everything is all right.

But if I have also the function
$crud->add_fields('my_id');

it's when the design is not correct.

I realised that happens as well with the edit.
If I have only the function
$crud->callback_edit_field('my_id', array($this, 'my_select'))

it's ok, but the design is not ok if I have also the function
$crud->edit_fields('my_id');


Any other idea?

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

Posted 08 March 2012 - 22:04 PM

Just add the javascript and the css of chosen and you will not have any problem. (This is just an off the record solution ;) ), add this BEFORE the call of the render() method as normal


$crud->set_css('assets/grocery_crud/css/jquery_plugins/chosen/chosen.css');
$crud->set_js('assets/grocery_crud/js/jquery_plugins/jquery.chosen.min.js');
$crud->set_js('assets/grocery_crud/js/jquery_plugins/config/jquery.chosen.config.js');

cesaret_2000
  • profile picture
  • Member

Posted 09 March 2012 - 08:44 AM

Hi again.

I tried it already, and I'm afraid it's not working neither. It's a weird bug, isn't it? If you have any other idea, I'll appreciate it.

Thanks Johnny.

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

Posted 09 March 2012 - 19:06 PM

Can you have as an attachment the html view page source of your page?

Thank you

cesaret_2000
  • profile picture
  • Member

Posted 12 March 2012 - 09:32 AM

Hi Johnny.

Actually I can't, because I decided to change this part of my application and to use a temporary table instead of a custom select. So, I don't need the callback.

Thanks any way for the feedback.