Skip to content

Commit

Permalink
Add datepicker widget to date fields
Browse files Browse the repository at this point in the history
Resolves #56
  • Loading branch information
shadyvb committed Feb 3, 2014
1 parent 11cf9fb commit 1e86e7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions includes/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function enqueue_scripts( $hook ) {
wp_enqueue_style( 'select2' );
wp_enqueue_script( 'select2' );
wp_enqueue_script( 'underscore' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.min.css', array(), '1.10.3' );
wp_enqueue_script( 'stream-notifications-form', WP_STREAM_NOTIFICATIONS_URL . '/ui/js/form.js', array( 'underscore', 'select2' ) );
wp_localize_script( 'stream-notifications-form', 'stream_notifications', $this->get_js_options() );
}
Expand Down
11 changes: 11 additions & 0 deletions ui/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ jQuery(function($){

_.templateSettings.variable = 'vars';

$.datepicker.setDefaults({
dateFormat: "yy-mm-dd"
});

var types = stream_notifications.types,
i,

Expand Down Expand Up @@ -42,6 +46,12 @@ jQuery(function($){
formatResult: select2_format
},

datify = function( elements ) {
$( elements ).each( function() {
$(this).datepicker();
});
},

selectify = function( elements, args ) {
args = args || {};
$.extend( args, select2_args );
Expand Down Expand Up @@ -191,6 +201,7 @@ jQuery(function($){
$this.after( tmpl_options( $.extend( options, { index: index } ) ) );
selectify( $this.parent().find('select') );
selectify( $this.parent().find('input.tags, input.ajax'), { tags: [] } );
datify( $this.parent().find('.type-date') );
})
;

Expand Down
2 changes: 1 addition & 1 deletion views/rule-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<% } %>
</select>
<% } else { %>
<input type="text" name="triggers[<%- vars.index %>][value]" class="trigger-value <% if ( vars.tags ){ %>tags<% } %> <% if ( vars.ajax ){ %>ajax<% } %>">
<input type="text" name="triggers[<%- vars.index %>][value]" class="trigger-value type-<%- vars.type %> <% if ( vars.tags ){ %>tags<% } %> <% if ( vars.ajax ){ %>ajax<% } %>">
<% } // endif%>
</div>
</div>
Expand Down

0 comments on commit 1e86e7a

Please sign in to comment.