⚠ 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

change_field_type not working



tomfrew
  • profile picture
  • Member

Posted 24 April 2012 - 22:55 PM

Hi,

I'm trying to use change_field_type to pre fill a value but when I load the page the field type has changed but the value is always blank. it seem to ignore the 3rd paramater.

my code:
[php]


$crud->change_field_type('order_id', 'number', $value);

[/php]

I've also tried:

[php]

$crud->change_field_type('order_id', 'text', '3');

[/php]


This issue also happens with the examples without any changes.

Does anyone know what could be causing this?

Thanks,
Tom

Luan
  • profile picture
  • Member

Posted 25 April 2012 - 00:32 AM

Hi there,

To do this you gotta use a callback. Also, check the list for the allowed field types.

Something like the 2 examples above, depends on what you need. You can also use callback_add_field and callback_edit_field for different situations.


$crud->callback_field('order_id',array($this,'callback_order_id'));

function callback_order_id($value, $primary_key){
$this->db->select('order_id')->where('id',$primary_key);
$result = $this->db->get('deposit')->row();
$order_id = $result->order_id;

return "<input type='text' name='order_by' class='numeric' value='$order_id' '";
}

//////// OR /////////
function callback_order_id($value, $primary_key){

return "<input type='text' name='order_id' class='numeric' value='$value' '";
}



tomfrew
  • profile picture
  • Member

Posted 25 April 2012 - 02:54 AM

Hi,

Thanks for your suggestions but neither work with what i'm trying to do. Basically the 'order_details' are items in an order and are filtered by which order they belong to using a url /order_details/$order_id

Here is a simplified version of the function:
[php]
function order_details($id = NULL)
{
$crud = new grocery_CRUD();

if (isset($id)) {
$crud->where('order_id',$id);
};

$crud->set_table('order_details');
$crud->set_subject('Item');
$output = $crud->render();

$this->_output($output);
}[/php]

What i'm trying to do is when the use clicks 'add item' the order id is pre populated.

Based on the examples - http://www.grocerycrud.com/documentation/options_functions/change_field_type

I tried the following but it nothing shows as the value.


[php]
function order_details($id = NULL)
{
$crud = new grocery_CRUD();
$crud->set_table('order_details');
$crud->set_subject('Item');

if (isset($id)) {
$crud->where('order_id',$id);
$crud->change_field_type('order_id', 'number', $id);
};

$output = $crud->render();
$this->_output($output);
}[/php]

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

Posted 25 April 2012 - 05:42 AM

I am sorry but the third parameter only works with the hidden fields for now. I just updated the webiste to other people also know.

tomfrew
  • profile picture
  • Member

Posted 25 April 2012 - 13:45 PM

Oh ok. Thanks.