Jump to content


[ANSWERED] change_field_type "enum" and values as array

change_field_type

  • Please log in to reply
9 replies to this topic

#1 Cèsar Martí

Cèsar Martí

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 05 March 2012 - 10:42 AM

I'd like to create a custom drop down list. I think that's possible with the function change_field_type, using the type enum. 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.

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,099 posts
  • LocationLondon

Posted 06 March 2012 - 10: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.
Posted Image

#3 vnt

vnt

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts

Posted 07 March 2012 - 08:07 PM

I want to add this feature at a future release to have for example:

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

It's a great idea!

#4 Vuong

Vuong

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 15 March 2012 - 02: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>';
}


#5 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 07 May 2012 - 07:38 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>';
}


Worked like a charm!


But it would be good the

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

Thanks!

#6 mrtakdnz

mrtakdnz

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 25 May 2012 - 06: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!

#7 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,099 posts
  • LocationLondon

Posted 26 May 2012 - 08:09 PM

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

#8 mrtakdnz

mrtakdnz

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 27 May 2012 - 07:37 AM

awesome! thanks much.


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



#9 bluepicaso

bluepicaso

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationIndia

Posted 27 August 2012 - 02:43 PM

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

Harpreet Singh Bhatia
[web developer, programmer, entrepreneur]
Portfolio: TheCodingBox


Follow Me: facebook.png twitter.png googleplus.pngskype.png


#10 Evgen Knizhnik

Evgen Knizhnik

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 18 February 2014 - 10: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;
    }







Also tagged with one or more of these keywords: change_field_type

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users