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.052 seconds

First of all... I have to congratulate you guys for the awesome tool... I came here only to see what this thing was up to and I have to tell that I'm very impressed with what this tool can do. French guys are making a revolution on Joomla... first with Seblod and now Cook...
Griiettner (forum)

Get Started