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

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started