⚠ 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

extra parameters for callbacks



jean-baptiste
  • profile picture
  • Member

Posted 22 February 2013 - 14:16 PM

Hello,

In the Offices example, GroceryCrud generates the following input code for the phone field :

 

<input type="text" maxlength="50" value="+61 2 9264 2451" name="phone" id="field-phone">

However, in the callback_edit_field example, the function edit_field_callback_1 has only two parameters $value and $primary_key, to modify the input :

 

function edit_field_callback_1($value, $primary_key)
{
return '+30 <input type="text" maxlength="50" value="'.$value.'" name="phone" style="width:462px">';
}

Is there a way to get the other attributes (type, maxlength ...) ?

 

For instance :

 

function edit_field_callback_1($value, $primary_key, $type, $name, $style, $maxlength)
{
return '+30 <input type="'.$type.'" maxlength="'.$maxlength.'" value="'.$value.'" name="'.$name.'" style="'.$style.'">';
}

 

 


jean-baptiste
  • profile picture
  • Member

Posted 22 February 2013 - 14:49 PM

I have an extra question : is it possible to pass the $value and $primary_key parameters to the edit_field_callback_1() function because of the following line in the grocery_crud.php library ?

 

protected function get_edit_input_fields($field_values = null)
{
...
$field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values);
...
}

davidoster
  • profile picture
  • Member

Posted 22 February 2013 - 16:50 PM

This is not an easy question to answer. A lot of things are involved in order to get the layout of the fields like this.

For changing the field just call the field_type function within GroceryCRUD. It's the safest way!

For the maxlength (that I know of) isn't that easy to answer. It depends on the theme you are using, on the css setting and the value (if exists) on the library (grocery_crud.php library I mean).


jean-baptiste
  • profile picture
  • Member

Posted 25 February 2013 - 13:54 PM

Thanks for your answer, but I don't want to change the type of the field, I just want to re-use the type of the field detected in the database by GroceryCrud.


davidoster
  • profile picture
  • Member

Posted 26 February 2013 - 11:21 AM

You mean get the value of the field or the values of some of the parameters on the input?


jean-baptiste
  • profile picture
  • Member

Posted 26 February 2013 - 13:25 PM

Hello,

I mean the parameters (i.e. the HTML attributes) of the input field. To take the example of the Offices example in the GroceryCrud documentation, GC can automaticaly generate the input field for the phone entry from the SQL field properties in the database :

<input type="text" maxlength="50" value="+61 2 9264 2451" name="phone" id="field-phone">

If you write a callback to add a +30 behind the phone number and you fill the HTML parameters by hands (as in the callback_edit_field example)

function edit_field_callback_1($value, $primary_key)
{
return '+30 <input type="text" maxlength="50" value="'.$value.'" name="phone" style="width:462px">';
}

and a few days later you change the SQL phone field to a size of 100 caracters in the database or change the type to INT, you must remember to change the callback code. This would not the case if you could get those parameters the database (and from GC has it knows it).

 

In other words : The GC documentation says about callback_edit_field :

 

To your callback you will take two parameters . 1st the value of the field and 2nd the primary key value of the record you just edited.

 

 

But It could be useful if we could pass more parameters to the callback (instead of only the value of the field and the primary key value) : every parameters that GC would use to generate the input field HTML if we did'nt write a callback.