⚠ 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 forum is read-only and soon will be archived. ⚠


dblanco

Member Since 07 Dec 2012
Offline Last Active Mar 13 2013 01:04 PM
-----

Topics I've Started

Html select field disappears in the edition (dropdown)

26 December 2012 - 02:20 PM

I have a problem to present a select option, from a relationship based on the edit screen (1-N).

With this configuration:
       $this->grocery_crud->set_table('contactos');

       $this->grocery_crud->set_relation('id_motivo', 'motivos', 'motivo');
            $this->grocery_crud->set_relation('id_usuario', 'usuarios', '{nombre} {apellido}');
            
       $this->grocery_crud->change_field_type('leido', 'true_false');
            $this->grocery_crud->change_field_type('fecha', 'datetime');
            $this->grocery_crud->change_field_type('fecha_leido', 'datetime');
                
         $this->grocery_crud->edit_fields('fecha','id_motivo', 'nombre', 'email', 'mensaje', 'leido');
       $this->grocery_crud->callback_edit_field('leido', array($this,'_leidoo_formato'));
            $this->grocery_crud->callback_update(array($this,'_editar_registro'));        
            
I add the image (Attached File  26122012_1.jpg   40.64K   858 downloads) )where you can see that initially presented correctly the edit form. Where in the dropdown is selected "Consulta". But when you click to select other "Motivo" the combo disappears (Attached File  26122012_2.jpg   40.33K   901 downloads).

With another click on the place where it should be the dropdown, you can edit the field, but do not select an option from the database (Table Motivos). As this edition is disabled? (Attached File  26122012_3.jpg   43.99K   748 downloads) It should not be possible to edit the value, select one of the options in the database.
Unable to re-display the html select after these actions.

Using these versions:
Codeigniter 2.0
Grocery Crud 1.3.3
Browser: Mozilla Firefox 17.0.1.

What can be the problem? Thanks for your time and help.

field_type

14 December 2012 - 09:40 PM

I try to create a hidden field with this configuration:

$this->grocery_crud->edit_fields('nombre','apellido', 'email', 'usuario', 'habilitado', 'usuario_old', 'email_old');
$this->grocery_crud->field_type('usuario_old', 'hidden', 'usuarioviejo');
$this->grocery_crud->field_type('email_old', 'hidden', 'emailold');

I get the following error:


A PHP Error was encountered

Severity: Notice
Message: Undefined property: stdClass::$extras
Filename: libraries/grocery_crud.php
Line Number: 2133

Using these versions:
Codeigniter 2.0
Grocery Crud 1.3

For the versions listed in the documentation, it should work. Is there a problem?

getState

14 December 2012 - 03:33 AM

This method can take values ​​as add, insert, or insert_validation. When each of them is returned? or what is the difference between them?

The same with these others: edit, update, update_validation.

Thanks

callback_before_insert & callback_insert

08 December 2012 - 02:35 PM

These two functions can not be used together. Looking at the implementation of function db_insert in the file libraries/grocery_crud.php can be viewed:

    protected function db_insert($state_info)
    {
1.   $validation_result = $this->db_insert_validation();
        
2.   if($validation_result->success)
        {
3.       $post_data = $state_info->unwrapped_data;
            
4.       $add_fields = $this->get_add_fields();

5.       if($this->callback_insert == null)
            {
6.           if($this->callback_before_insert != null)
                {
7.               $callback_return = call_user_func($this->callback_before_insert, $post_data);
              
8.               if(!empty($callback_return) && is_array($callback_return))
9.                   $post_data = $callback_return;
10.               elseif($callback_return === false)
11.                   return false;
                }
                
12.           $insert_data = array();
13.           $types = $this->get_field_types();
14.           foreach($add_fields as $num_row => $field)
                {
15.               if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name]))
                    {
16.                   if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '')
                        {
17.                       $insert_data[$field->field_name] = null;
                        }
18.                   elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date')
                        {
19.                       $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]);
                        }
20.                   elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly')
                        {
21.                       //This empty if statement is to make sure that a readonly field will never inserted/updated
                        }    
22.                   elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'set')
                        {
23.                       $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : '';
                        }                                            
24.                   elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){
25.                       $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)).
                                                                        substr($post_data[$field->field_name],10);
                        }
26.                   else
                        {
27.                       $insert_data[$field->field_name] = $post_data[$field->field_name];    
                        }                        
                    }
                }
    
28.           $insert_result =  $this->basic_model->db_insert($insert_data);
                    
29.           if($insert_result !== false)
                {
30.               $insert_primary_key = $insert_result;
                }
31.           else
                {
32.               return false;
                }
                
33.           if(!empty($this->relation_n_n))
                {
34.               foreach($this->relation_n_n as $field_name => $field_info)
                    {
35.                   $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ;
36.                   $this->db_relation_n_n_update($field_info, $relation_data  ,$insert_primary_key);
                    }
                }
                
37.           if($this->callback_after_insert != null)
                {
38.               $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key);
                    
39.               if($callback_return === false)
                    {
40.                   return false;
                    }
                    
                }
41.       }else
            {
42.               $callback_return = call_user_func($this->callback_insert, $post_data);
                    
43.               if($callback_return === false)
                    {
44.                   return false;
                    }
       }
45.       if(isset($insert_primary_key))
46.           return $insert_primary_key;
47.       else
48.           return true;
        }
49.   return false;
    }

For example having this setup:
       $this->grocery_crud->callback_before_insert(array($this,'_prepara_datos_agregar'));
            $this->grocery_crud->callback_insert(array($this,'_insertar_registro'));

When trying to create a record, coming in on the line 41 because there is a function callback_insert (_insertar_registro).
Then this piece of code, lines 42-44, ignores the execution of the function callback_before_insert (_prepara_datos_agregar).

I understand then that there is no way to use both functions together. Is this correct?

Custom error message

07 December 2012 - 09:38 PM

I want that when the system can not insert a record, the message indicated report at runtime.

Using the following code does not work:

$this->grocery_crud->callback_insert(array($this,'_insertar_registro'));

function _insertar_registro($post_array) {
... control data with error....

$this->grocery_crud->set_lang_string('insert_error', 'No inserto');
return FALSE;
}

Displays on screen: 'Ocurrio un error durante la insercion.'

because in the selected language file is indicated:

$lang['insert_error'] = 'Ocurrio un error durante la insercion.';

but not the message specified by the function insertar_registro.

What's wrong? thanks