Jump to content


How to modify selectbox

selectbox option value

  • Please log in to reply
9 replies to this topic

#1 pbcomput

pbcomput

    Member

  • Members
  • PipPip
  • 19 posts

Posted 18 December 2013 - 01: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.

 



#2 jinbatsu

jinbatsu

    Member

  • Members
  • PipPip
  • 23 posts

Posted 18 December 2013 - 02:29 PM

Hello,

 

Like this:

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

http://www.grocerycr...#dropdown-field



#3 pbcomput

pbcomput

    Member

  • Members
  • PipPip
  • 19 posts

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



#4 Eric W.

Eric W.

    Newbie

  • Members
  • Pip
  • 1 posts

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



#5 jinbatsu

jinbatsu

    Member

  • Members
  • PipPip
  • 23 posts

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.grocerycr...ions/add_fields

edit_fields: http://www.grocerycr...ons/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.



#6 pbcomput

pbcomput

    Member

  • Members
  • PipPip
  • 19 posts

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



#7 jinbatsu

jinbatsu

    Member

  • Members
  • PipPip
  • 23 posts

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).



#8 pbcomput

pbcomput

    Member

  • Members
  • PipPip
  • 19 posts

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:



#9 jinbatsu

jinbatsu

    Member

  • Members
  • PipPip
  • 23 posts

Posted 19 December 2013 - 01: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.


#10 pbcomput

pbcomput

    Member

  • Members
  • PipPip
  • 19 posts

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.







Also tagged with one or more of these keywords: selectbox, option, value

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users