⚠ 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 set default value in dropdown during add state



Peter

Peter
  • profile picture
  • Member

Posted 16 April 2015 - 07:11 AM

Please someone help, I want to know how to set default value for dropdown during add state, I know that if record exists already on database it selects dropdown automatically during edit state, but during add record, I would like to keep default value.

$crud->field_type("status",'dropdown',array( '0'=>'rejected', '1'=>'approved','2'=>'Yet to moderate', '3'=>'Pending') );

By default I would like to select pending that is 3, please help me how this can be done.

 


maxmax

maxmax
  • profile picture
  • Member

Posted 16 April 2015 - 12:31 PM

Hello there. I use hidden fields to pass the defaults, then I set the selected values via jquery. Then remember to unset the hidden field before insert/update.


Akshay Hegde

Akshay Hegde
  • profile picture
  • Member

Posted 17 April 2015 - 04:20 AM

Try this

              // Get state
	       $state = $crud->getState(); 

              // Call render function
               $output = $crud->render();

               if($state == 'add')
	       {
		$js='<script>$(\'select[name="status"] option[value="3"]\').attr("selected", "selected");</script>';
		$output->output .= $js;	
	       }

	       $this->_example_output($output);

Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 April 2015 - 06:36 AM

well u can use javascript to set the value for the dropdown

or there are solutions shared to set default add values ... check them out - those should help i believe


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 April 2015 - 06:39 AM

/topic/2260-do-javascript-function-after-ajax-list-finished/

 

read the following list - it will help u