Jump to content


Setting dropdown selected index

dropdown select

  • Please log in to reply
3 replies to this topic

#1 KaBaDaBrA

KaBaDaBrA

    grocery CRUD magician

  • Members
  • PipPipPip
  • 57 posts

Posted 20 March 2012 - 04:15 PM

Hi :D

I currently have a feature where the client can add models to a vehicle. For example when adding a new model, he inserts the model title and selects a vehicle from the dropdown. Kk...now the problem is the client wants the dropdown to remain on the previously selected item. So if he chose "BMW" and clicks save the selected should still be "BMW".

How can I achieve this?

I thought about using the "callback_after_insert" feature to save it as a session item and then using jQuery to set the selected index. Would this be a good way of doing it or is there an easier way using GCRUD?

TIA!!! :)
Grocery CRUD - Categories and Subcategories - Demo and Step by Step here: http://demo.edynamic..._management/add

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,099 posts
  • LocationLondon

Posted 20 March 2012 - 06:54 PM

What a weird request! You can do it only with javascript. Just change the clearForm functionallity. So for each dropdown just don't clear it. So you will just go to:
assets/grocery_crud/themes/flexigrid/js/flexigrid-add.js - line 92
(I have the changes with a big arrow)
function clearForm()
{
  $('#crudForm').find(':input').each(function() {
		 switch(this.type) {
			 case 'password':
			 case 'select-multiple':
			 //case 'select-one': // <--------------------------------------------------------------------------------------------------------------
			 case 'text':
			 case 'textarea':
				 $(this).val('');
				 break;
			 case 'checkbox':
			 case 'radio':
				 this.checked = false;
		 }
	 });
  /* Clear upload inputs  */
  $('.open-file,.gc-file-upload,.hidden-upload-input').each(function(){
   $(this).val('');
  });
  $('.upload-success-url').hide();
  $('.fileinput-button').fadeIn("normal");
  /* -------------------- */
  $('.remove-all').each(function(){
   $(this).trigger('click');
  });
/*
//CHANGE THIS <--------------------------------------------------------------------------------------------------------------
  $('.chosen-multiple-select, .chosen-select, .ajax-chosen-select').each(function(){
   $(this).trigger("liszt:updated");
  });
*/
/* TO THIS */ <-----------------------------------------------------------------------------------------------------------------
  $('.chosen-multiple-select').each(function(){
   $(this).trigger("liszt:updated");
  });
}

Posted Image

#3 KaBaDaBrA

KaBaDaBrA

    grocery CRUD magician

  • Members
  • PipPipPip
  • 57 posts

Posted 20 March 2012 - 08:13 PM

I know right?! Odd request but apparently needs to work that way :huh: Thanks muchos much!!!
Grocery CRUD - Categories and Subcategories - Demo and Step by Step here: http://demo.edynamic..._management/add

#4 Baldrick

Baldrick

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 18 September 2012 - 10:37 AM

This topic is kind of old, but I wanted to add my contribution in case anyone led here via search or google would find it useful.

I ran into something similar (so I guess it's not so odd :P ) and since I wanted to disturb core files as little as possible, this is how I did it:

In assets/grocery_crud/themes/xxx/js/xxx-add.js (xxx being datatables/flexigrid/whatever), find the clearForm() function, and change the first line:

$('#crudForm').find(':input').each(function() {



to

$('#crudForm').find(':input').not('.noclear').each(function() {



And then make sure the fields you don't want to reset have the "noclear" CSS class. For example, by inserting this into the view's HTML when getState == 'add':

           	 <script type=\"text/javascript\">
                $(document).ready(function(){
                        $('#field-whatever,#field-something_or_other,#field-thisoneaswell').addClass('noclear');
           	 });
                </script>

Or by using appropriate callbacks.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users