<commit_before>App.Datepicker = {
  instances: [],
  initialize: function($elements) {
    var that = this;

    $(document).one('turbolinks:before-cache.Datepicker', function() {
      that.teardown();
    });

    this.add( $elements );
  },
  add: function($elements) {
    var that = this;

    $elements.each(function() {
      var $el = $(this);
      var options = {
        dateFormat: 'yy-mm-dd'
      };

      if ( $el.data('datepicker') ) {
        // Already initialized
      } else {
        that.instances.push( $el );
      }

      $el.datepicker( options );
    });
  },
  teardown: function() {
    for ( var i = this.instances.length - 1; i >= 0; i-- ) {
      $(this.instances[i]).datepicker('destroy');
    }
    this.instances = [];
  }
};

App.pageLoad.push(function() {
  App.Datepicker.initialize( $('.form-group[class*="_scheduled_date"] input[name$="[scheduled_date]"]').filter(':visible') );
  App.Datepicker.initialize( $('.form-group [data-datepicker="true"]').filter(':visible') );
});<commit_msg>If a datepicker input is required, set the date to today's date by default<commit_after>App.Datepicker = {
  instances: [],
  initialize: function($elements) {
    var that = this;

    $(document).one('turbolinks:before-cache.Datepicker', function() {
      that.teardown();
    });

    this.add( $elements );
  },
  add: function($elements) {
    var that = this;
    var date = new Date();
    var year = date.getFullYear().toString();
    var month = date.getMonth().toString().padStart(2, 0);
    var day = date.getDay().toString().padStart(2, 0);
    var defaultDate = year + '-' + month + '-' + day;

    $elements.each(function() {
      var $el = $(this);
      var options = {
        dateFormat: 'yy-mm-dd'
      };

      if ( $el.data('datepicker') ) {
        // Already initialized
      } else {
        that.instances.push( $el );
      }

      $el.datepicker( options );

      if ( $el.hasClass('required') && $el.datepicker('getDate') == null ) {
        $el.datepicker('setDate', defaultDate);
      }
    });
  },
  teardown: function() {
    for ( var i = this.instances.length - 1; i >= 0; i-- ) {
      $(this.instances[i]).datepicker('destroy');
    }
    this.instances = [];
  }
};

App.pageLoad.push(function() {
  App.Datepicker.initialize( $('.form-group[class*="_scheduled_date"] input[name$="[scheduled_date]"]').filter(':visible') );
  App.Datepicker.initialize( $('.form-group [data-datepicker="true"]').filter(':visible') );
});
{'fraction_non_alphanumeric': 0.19631410256410256, 'fraction_numerical': 0.003205128205128205, 'mean_word_length': 2.800608828006088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3435082', 'n_tokens_mistral': 837, 'n_tokens_neox': 804, 'n_words': 145}