Jump to content


rafael84

Member Since 24 Dec 2011
Offline Last Active Feb 16 2013 01:33 AM
-----

Posts I've Made

In Topic: Default field values (for add form)

02 January 2012 - 12:23 AM

Thanks Johnny, you're right. So here's another approach:

File: assets/grocery_crud/themes/flexigrid/js/Flexigrid-add.js
$(function(){
...
$("#FormLoading").ajaxStart(function(){
  $(this).show();
});
$("#FormLoading").ajaxStop(function(){
  $(this).fadeOut('slow');
});

clearForm(); // NEW

$('#crudForm').submit(function(){
...
	    }
}
...
function clearForm() {
$('#crudForm').find(':input').each(function() {
  var default_value = $(this).attr('name') + '_default_value';
  try { var value = eval(default_value); } catch(err) {}

  switch(this.type) {
   case 'password':
   case 'select-multiple':
   case 'select-one':
   case 'text':
   case 'textarea':
    if (typeof(value) === 'undefined') {
	 $(this).val('');
    } else {
	 $(this).val(value);
    }
    break;
   case 'checkbox':
   case 'radio':
    if (typeof(value) === 'undefined') {
	 this.checked = Boolean(value);
    } else {
	 this.checked = false;
    }
  }
});

$('.remove-all').each(function(){
  $(this).trigger('click');
});
}

In my view, I have declared some javascript variables in order to define the default values for some fields. Like this:
<html>
...
<body>
<script type='text/javascript'>
var order_date_default_value = '2012-01-01';
var lenses_default_value = 'FAR';
</script>
...
<?php echo $output; ?>
...
</html>

As you can see above, there default values for two fields, the order_date and the lenses field.

What do you think about this solution?

In Topic: Portuguese language file

28 December 2011 - 01:45 AM

Cool! Let's make grocery CRUD the best library in the world! :-)

In Topic: Default field values

27 December 2011 - 08:27 PM

Hi coderr, check my suggestion here: http://www.grocerycr...s-for-add-form/

In Topic: Date & Time Formats

27 December 2011 - 02:07 PM

I think that way too. :-)

In Topic: ID attributes in edit.php and add.php

26 December 2011 - 12:43 AM

Thanks Johnny, I really appreciate your attention to my suggestion.
I just posted my language file, which is actually a Brazilian Portuguese version.
Thankfully someone else has already posted the Spanish translation too.