⚠ 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 modify selectbox



pbcomput
  • profile picture
  • Member

Posted 18 December 2013 - 13:44 PM

Hi,

 

I am new to grocery crud. Please help me to achieve the following output on select box.

 

I took ENUM type on table of user to manage user type. I am getting below output.

 

<select id="field-member_type" name="member_type" class="chosen-select chzn-done" data-placeholder="Selectionner Member type">

<option value=""></option>

<option value="u">user</option>

<option value="s">student</option>

</select>

 

But I need the output like this.

 

<select id="field-member_type" name="member_type" class="chosen-select chzn-done" data-placeholder="Selectionner Member type">

<option value=""></option>

<option value="u">user</option>

<option value="s">student</option>

</select>

 

help me to solve this issue.

 

Thanks.

 


jinbatsu
  • profile picture
  • Member

Posted 18 December 2013 - 14:29 PM

Hello,

 

Like this:

$crud->field_type('member_type','dropdown', array('u' => 'user, 's' => 'student'));

http://www.grocerycrud.com/documentation/options_functions/field_type#dropdown-field


pbcomput
  • profile picture
  • Member

Posted 19 December 2013 - 06:46 AM

Hi jinbatsu,
 
Thanks for the help. It worked for me.! :)
 
I am also having issue for hide the last field on edit. when I try to hide the last field by below code, the selectbox for other fields width auto removed I don't know why.! 
 
my code to hide last field is like below
 

$crud->unset_edit_fields('reg_date');

 

I also tried change field type method but it also not worked.!?  :huh:

 

$crud->change_field_type('reg_date','invisible');

 

Please note that, I am only facing the issue while I do Edit. Its working fine on Add.

 

Thanks


Eric W.
  • profile picture
  • Member

Posted 19 December 2013 - 06:57 AM

Hi all,

I had a similar challenge.

Initially I had a table with the options then would call the set_relation function.

But now this option by jinbatsu   has improved the performance on my app!!! thanks


jinbatsu
  • profile picture
  • Member

Posted 19 December 2013 - 09:48 AM

Hi pbcomput,

 

Did you try with this methode?

    $crud->add_fields('field1','field2','reg_date');
    $crud->edit_fields('field1','field2');

add_fields : http://www.grocerycrud.com/documentation/options_functions/add_fields

edit_fields: http://www.grocerycrud.com/documentation/options_functions/edit_fields

 

And don't forget to remove the $crud->fields variable. I mean for this case just don't use fields, but use add_fields and edit_fields.

Try it.

 

Hello Eric W.

I just read the API documentation, this grocerycrud is flexible enaugh for regular web application.


pbcomput
  • profile picture
  • Member

Posted 19 December 2013 - 10:04 AM

Hi jinbatsu,

 

Nops..! Its not working..!  :(

 

I don't know why its behaving unusual..!  :huh:

 

Please check attached image, and check the selectbox size.

 

1C35BWW.png

 

Thanks


jinbatsu
  • profile picture
  • Member

Posted 19 December 2013 - 11:19 AM

pbcomput, can you show your controller code?

and put in code format (in this forum, it is in one left beside quote icon or one right after image icon).


pbcomput
  • profile picture
  • Member

Posted 19 December 2013 - 11:26 AM

Hi jinbatsu,

 

Thanks for letting me know the code option. I was searching for it but was not able to find it.! :P  Here is my code of controller.

function users()
	{
	    if($this->checkSession())
		{
			$crud = new grocery_CRUD();
			
			$crud->where('status','c');
			$crud->where('member_type','u');
		        $crud->set_table('member');
			$crud->set_subject('User');
			
		    $crud->columns('member_id','profile_photo','first_name','last_name','age','username','email');
			/*$crud->add_fields('member_type','profile_photo','first_name','last_name','age','username','email','news_letter_subscription','status');
			$crud->edit_fields('member_type','profile_photo','first_name','last_name','age','username','email','news_letter_subscription','status');*/
			$crud->field_type('member_type','dropdown', array('u' => lang('user'), 's' => lang('specialist')));
			$crud->field_type('news_letter_subscription','dropdown',array('y' => lang('sub'), 'n' => lang('nosub')));
			$crud->field_type('status','dropdown', array('i' => lang('inactive'), 'c' => lang('confirmed'), 'b' => lang('banned')));
			$crud->display_as('member_id',lang('user').' '.lang('id'))
				 ->display_as('first_name',lang('first_name'))
				 ->display_as('last_name',lang('last_name'));
			
			
			$crud->required_fields('first_name','last_name','age','status');
			$crud->unset_edit_fields('password','json_status','reg_date','activation_code');
			//$crud->change_field_type('last_login_date','invisible');
			$crud->unset_add_fields('json_status','reg_date','activation_code');
			$crud->callback_edit_field('email',array($this,'email_callback'));
			$crud->callback_edit_field('username',array($this,'username_callback'));
			
			
			
			//$crud->callback_edit_field('reg_date',array($this,'reg_date_callback'));
			//$crud->callback_edit_field('last_login_date',array($this,'last_login_callback'));

		 	
		    $output  = $crud->render();
		    $this->_users_output($output);
		}
	}
	
	function email_callback($value, $primary_key)
	{
	    return $value;
	}
	
	function username_callback($value, $primary_key)
	{
	    return $value;
	}
	
	function reg_date_callback($value, $primary_key)
	{
	    return $value;
	}
	
	function last_login_callback($value, $primary_key)
	{
	    return $value;
	}

	public function _users_output($output = null)
	{
		$data = array();
		$data['main_content'] = 'backoffice/users';
		$data = array_merge($data,(array)$output);
		$this->load->view('backoffice/backoffice_template', $data);	
	}

Please check it and let me know where I am doing wrong.!  :rolleyes:


jinbatsu
  • profile picture
  • Member

Posted 19 December 2013 - 13:08 PM

First, I think we should choose either using 
1. $crud->fields 
or 
2. $crud->add_fields & $crud->edit_fields.
 
But in your code, you did choose either one.
The $crud->columns is only for list.
 
I don't know for sure, but this is my undertanding about this grocerycrud from their examples.
 
Second, if the display is not correct like that above (screenshot), I think it's just because conflict with others CSS rules.

pbcomput
  • profile picture
  • Member

Posted 21 December 2013 - 08:06 AM

Hi jinbatsu,

 

Thanks for your help. I will check it by removing $crud->fields. And yes columns are for listing only. 

 

I think the issue is may not related to crud but issue is related to css or js. :(

 

Thanks.