⚠ 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

how to set upload field dynamically on condition that a field has some specific value



Emad Karhily
  • profile picture
  • Member

Posted 14 January 2017 - 00:04 AM

My database is something generic and dynamic so there is a table which define fields as triple of (key,value,type) where type is linked to other table called field_type that define available field types in the application.
I tried so hard to set upload field and change field type upon a condition depend on the type value of the table row but fail to work it out.
Here is what I try to do:

        $crud->columns('key', 'value','type');
        $crud->required_fields('value');

if ($crud->getState() == 'edit') {
            $field_id = $this->uri->segment(5);
            $_SESSION['field_id'] = $field_id;
            $field = $this->fields->get($field_id);
            $field_type = $this->field_types->get($field['field_type']);
            $field_type = $field_type['type'];
            $crud->fields('value');
            if ($field_type == 'file') {
                $crud->set_field_upload('value');
                $crud->callback_before_upload(array($this, '_callback_upload_image'));
            }
        }

Amit Shah
  • profile picture
  • Member

Posted 18 January 2017 - 02:20 AM

Hi EHMAD

 

There is a catch i believe to the grocery crud - for you to be able to set a field as upload, you need to have the same as a field in the table. If you dont, it wont set it as upload. Do you have a value field available in the table? if not, i will recommend you add the same.. and check.