Answers.Body: <p>You can set a datepicker's default value in the <code>setDefaultValues()</code> method of the form.  Here is a snippet of code that sets a date to today if none exists, and to a saved date if it does:</p>
  
  
  
  <pre><code>    if (empty($data['thank_you_date'])) {
        $defaultValues['thank_you_date'] = date('Y-m-d');
      } else {
        $defaultValues['thank_you_date'] = $data['thank_you_date'];
      }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-23T19:52:00.260Z
Answers.LastActivityDate: 2019-04-23T19:52:00.260Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>How does one add a default value in one of Datepicker fields while adding or editing Relationship? For example, set today's date as a start date at Enabled checkbox check and as the end date if un-checked.  Should it be a custom piece of jQuery code or it's better to alter jcalendar.tpl? If latter, how one defines "Add/Edit Relationship" modal frame has been triggered and not, say, "Add/Edit Membership?" one.</p>
  
Tags: <best-practice><dates>
Title: Page - specific Datepicker config in jcalendar.tpl
ThreadText: # Page - specific Datepicker config in jcalendar.tpl
  
  (Asked by: username_0 on 2015-10-25)
  
  How does one add a default value in one of Datepicker fields while adding or editing Relationship? For example, set today's date as a start date at Enabled checkbox check and as the end date if un-checked. Should it be a custom piece of jQuery code or it's better to alter jcalendar.tpl? If latter, how one defines "Add/Edit Relationship" modal frame has been triggered and not, say, "Add/Edit Membership?" one.
  
  **Tags:** best-practice, dates
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-23. Score: 1
  
  You can set a datepicker's default value in the `setDefaultValues()` method of the form. Here is a snippet of code that sets a date to today if none exists, and to a saved date if it does:
  
  ```
      if (empty($data['thank_you_date'])) {
        $defaultValues['thank_you_date'] = date('Y-m-d');
      } else {
        $defaultValues['thank_you_date'] = $data['thank_you_date'];
      }
  
  ```
  
  
  ---
  
  