Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Default Value for Filters (Range,...) 03 Oct 2013 06:52 #11290

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  if ($('#filter_reportdate_from').val() == ""){
	  var dateDeb = new Date();
	  var leMois = Number(dateDeb.getMonth())+1;
	  var annee = dateDeb.getFullYear();
	  var laDateDeb = "01."+leMois+"."+annee;
	  $('#filter_reportdate_from').val(laDateDeb);
	  adminForm.submit()
  }
Just to know if my coding is correct : i want to set a range From filter field to the first day of the month if nothing has been chosen (so when the user first arrives on the page). (It works, i just want to know if i could code it better)

Please Log in or Create an account to join the conversation.

Last edit: by VeCrea.

Default Value for Filters (Range,...) 10 Oct 2013 00:13 #11361

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Better in PHP.

In the view file, BEFORE to call getItems()
$model->setState('filter.reportdate_from', $dateDeb->toSql());

Assuming $dateDeb is a JDate Object initializated as you want.
You must read the state before to set default value :
if (!$model->getState('filter.reportdate_from'))

Be careful with JDate::toSql() function (in my example) it is only supported by Joomla 3.0. You must use the helper to make this code cross compatible.
XxxxHelperDates::toSql($dateDeb)

Hope it helps.
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.051 seconds

For starters it's just so easy to design an app in a way that I'm used to i.e. database first then views followed by customization. The fork system is pure brilliance from a developer standpoint as I can override things and still add and update my projects with minimal effort! Truly amazing to be able to build components in Joomla using incremental refinement without having to do everything by hand. Thanks for the great tool! I am so much more productive now than ever and I can't imagine building components any other way!!!!
Dave (Forum)

Get Started