⚠ 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 forum is read-only and soon will be archived. ⚠


How to set default value in dropdown during add state


  • Please log in to reply
4 replies to this topic

#1 Peter

Peter

    Member

  • Members
  • PipPip
  • 25 posts

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.

 



#2 maxmax

maxmax

    Newbie

  • Members
  • Pip
  • 5 posts

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.



#3 Akshay Hegde

Akshay Hegde

    Member

  • Members
  • PipPip
  • 14 posts

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


#4 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

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



#5 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

Posted 19 April 2015 - 06:39 AM

http://www.grocerycr...-list-finished/

 

read the following list - it will help u






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users