⚠ 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

[ANSWERED] change_field_type "enum" and values as array



cesaret_2000
  • profile picture
  • Member

Posted 05 March 2012 - 10:42 AM

I'd like to create a [b]custom drop down list[/b]. I think that's possible with the function [b]change_field_type[/b], using the type [b]enum[/b]. How can I say the list of values? Any other idea to create a custom drop down list? Maybe using a temporary table and use the function set_relation instead of change_field_type?

Thanks a lot.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 06 March 2012 - 22:55 PM

Hello and sorry for the delayed answer.

I think that a temporary table will make your life easier. I want to add this feature at a future release to have for example:


$crud->change_field_type('jobTitle', 'enum', array('test','test1','test2'));


But still I don't have it so a quick solution is a temporary table as you said with set_relation.

vnt
  • profile picture
  • Member

Posted 07 March 2012 - 20:07 PM

[quote name='web-johnny' timestamp='1331074507' post='705']
I want to add this feature at a future release to have for example:

$crud->change_field_type('jobTitle', 'enum', array('test','test1','test2'));

[/quote]
It's a great idea!

Vuong
  • profile picture
  • Member

Posted 15 March 2012 - 14:55 PM

Did u try callback_field() function?


$crud->callback_field('column', array($this, 'field_callback'));
$crud->render().....
public function field_callback($value = NULL)
{
$options = array('a', 'b', 'c');
$option_tag = '';
foreach($options as $option)
{
$attribute = 'value="'.$option.'"';
if ($option == $value)
{
$attribute .= ' selected="selected"';
}
$option_tag .= "<option $attribute>$option</option>";
}
return '<select name="column">'.$option_tag.'</select>';
}

jcasanova
  • profile picture
  • Member

Posted 07 May 2012 - 19:38 PM

[quote name='Vuong' timestamp='1331823318' post='791']
Did u try callback_field() function?


$crud->callback_field('column', array($this, 'field_callback'));
$crud->render().....
public function field_callback($value = NULL)
{
$options = array('a', 'b', 'c');
$option_tag = '';
foreach($options as $option)
{
$attribute = 'value="'.$option.'"';
if ($option == $value)
{
$attribute .= ' selected="selected"';
}
$option_tag .= "<option $attribute>$option</option>";
}
return '<select name="column">'.$option_tag.'</select>';
}

[/quote]

Worked like a charm!


But it would be good the


$crud->change_field_type('jobTitle','enum', array('test','test1','test2'));


Thanks!

mrtakdnz
  • profile picture
  • Member

Posted 25 May 2012 - 18:04 PM

Awesome. But is there any way to use it like this:

$this->crud->change_field_type('lang', 'enum', array( 'English' => 'en', 'Russian' => 'ru' ));

and appears like:

<select>
<option value="en">English</option>
...

Thanks!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 26 May 2012 - 20:09 PM

Yes you can download the latest version from github: https://github.com/s.../zipball/master

mrtakdnz
  • profile picture
  • Member

Posted 27 May 2012 - 07:37 AM

awesome! thanks much.


[quote name='web-johnny' timestamp='1338062961' post='1997'] Yes you can download the latest version from github: https://github.com/s.../zipball/master [/quote]

bluepicaso
  • profile picture
  • Member

Posted 27 August 2012 - 14:43 PM

now since I was able to get the static add one, how can i show it in the list without "set_relation"??

Evgen Knizhnik
  • profile picture
  • Member

Posted 18 February 2014 - 22:22 PM

now since I was able to get the static add one, how can i show it in the list without "set_relation"??

$crud->callback_column('group_exercise_id',array($this,'list_group_exercise_id'));

 

public function list_group_exercise_id($value, $row)
    {
        $name = '';
        if($value==1){
            $name = 'Text 1';
        }
        if($value==2){
            $name = 'Text 2';
        }

        return $name;
    }