Jump to content


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

upload dynamically set_field_upload

  • Please log in to reply
1 reply to this topic

#1 Emad Karhily

Emad Karhily

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 14 January 2017 - 12: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'));
            }
        }


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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.







Also tagged with one or more of these keywords: upload, dynamically, set_field_upload

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users