Jump to content


Change Field Type After Render Or...?

field_type change_field_type

  • Please log in to reply
5 replies to this topic

#1 mrtakdnz

mrtakdnz

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 01 April 2013 - 12:05 PM

I have a config table like:

CREATE TABLE `wfbp_config` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`type` VARCHAR(20) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`slug` VARCHAR(20) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`title` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`description` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`value` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
        `values` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	PRIMARY KEY (`id`),
	UNIQUE INDEX `slug` (`slug`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB;

 

I store config values at this table but...

 

I need to change value's field_type by type's column value, like:

 

if ($type=='image')
    $this->crud->set_field_upload('value', $this->config->item('upload_path'));
elseif ($type=='text')
    $this->crud->field_type('value','text');
elseif ($type=='date')
    $this->crud->field_type('value','date');
elseif ($type=='dropdown')
    $this->crud->field_type('value','date', explode(',', $values));

/* etc... */

 

But i have to change this after rendering the crud. And it's impossible (i guess). And i cannot achieve this with callbacks!

 

Is there any way to solve this with this table structure or is there any suggestion for a new table structure (but not all config values in one row).

 

For now i'm using multiple crud pages with unique config. like: sitename/panel/config-string/tr/system/ or sitename/panel/config-images/tr/system/ etc... i want to merge this values.

 

Thanks in advance.

 

P.S. I try to get config values like this:

 

Model:

    function get_config($config_slug) {
        
        $this->db->where('slug', $config_slug)
            ->where('lang', LANG_STR);
        $qr = $this->db->get('config');
        
        if ($qr->num_rows() == 1) {
            return $qr->row()->config_value;
        } else {
            return false;
        }
        
    }

 

Helper:

    function config($config_slug) {
        
        $wf=& get_instance();
        $wf->load->model('site_model');
        
        return $wf->site_model->get_config($config_slug);
        
    }

 

 

Thanks again...

Attached Thumbnails

  • demo-config-table.jpg


#2 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 03 April 2013 - 04:13 PM

Well... there is (as far as I know) no way to do this with the "standard" GC form BUT! you may be able to create "ghost" (that don't really exist on the database) hidden fields for each type, change which one to show with jQuery and set the right value with a callback_before_insert/update.

 

something like... 

 

On the controller:

$this->crud->set_field_upload('value', $this->config->item('upload_path'));
$this->crud->field_type('value_text','text');
$this->crud->field_type('value_date','date');
$this->crud->field_type('value_date2','date', explode(',', $values));

 

I have set the set_field_upload to the existing table field because I think that it doesn't work otherwise...

 

And on the callback you just have to see what type you have actually chosen and overwrite the $post['value'] value with the correct form value (for example, if you have set text... $post['value']=$post['value_text'])

 

About the edit:

If you assume that you can't change the 'type', a simple callback_edit_field would suffice (you get the $id of the row, so you can query for the type to set the field_type accordingly). Otherwise, just can use the same method I proposed to the add.

 

Hope it helped!

 

P.D.: One more idea: You can have many GCs to administer the same database, so you may be able to create one, generic, for listing with the add form disabled and then one for each type, with the type as a read only field with only the add form enable. Of course, you will have to create an add button for each type but it is easier than the first way... (also, not that preaty :P)


Edited by Zalo, 03 April 2013 - 04:20 PM.


#3 mrtakdnz

mrtakdnz

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 05 April 2013 - 12:09 PM

actually javascript solution is useful. But when i remove a field_box it, table stripes cannot re render and it appears like this: attachment

 

when i remove 2.nd (or whatever) box:

 

white
grey => remove this
white
gray

 

 

result:

 

 

white
white
gray

 

Attached Thumbnails

  • Capture.JPG


#4 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 05 April 2013 - 05:17 PM

I suppose you need to run through, using js again to reimplement the background stripes.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#5 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 05 April 2013 - 06:51 PM

The stripes are just a class, "odd" for white ones and "even" for gray ones. You should be able to reset them with a js just as david said.

Keep in mind that each field-box has it's own id so you may even set them manually for each one (even the ones that you hide).



#6 mrtakdnz

mrtakdnz

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 05 April 2013 - 07:23 PM

oh yeah. My bad! sometimes i miss the point :) thanks for the help. so appreciated.







Also tagged with one or more of these keywords: field_type, change_field_type

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users