Setting dropdown selected index
- Single Page
Posted 20 March 2012 - 16:15 PM
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!!!
Posted 20 March 2012 - 18:54 PM
[b]assets/grocery_crud/themes/flexigrid/js/flexigrid-add.js - line 92[/b]
(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 20 March 2012 - 20:13 PM
Posted 18 September 2012 - 10:37 AM
I ran into something similar (so I guess it's not so odd ) and since I wanted to disturb core files as little as possible, this is how I did it:
In [b]assets/grocery_crud/themes/xxx/js/xxx-add.js [/b](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.