Skip to content

Commit

Permalink
Fix typo and do not add datepicker attribute if a timepicker field
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Nov 22, 2015
1 parent c4b5f89 commit b501ebe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions includes/CMB2_Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,11 @@ public function text_date( $args = array() ) {
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ),
) );

if ( $js_date_format = cmb2_utils()->php_to_js_dateformat( $this->field->args( 'date_format' ) ) ) {
$args['data-datepicker'] = '{ "dateFormat": "' . $js_date_format . '" }';
if ( false === strpos( $args['class'], 'timepicker' ) ) {
$js_date_format = cmb2_utils()->php_to_js_dateformat( $this->field->args( 'date_format' ) );
if ( $js_date_format ) {
$args['data-datepicker'] = '{ "dateFormat": "' . $js_date_format . '" }';
}
}

return $this->input( $args );
Expand All @@ -532,7 +535,7 @@ public function text_time( $args = array() ) {
) );

if ( $js_time_format = cmb2_utils()->php_to_js_dateformat( $this->field->args( 'time_format' ) ) ) {
$time_args['data-timepicker'] = '{ "timeFormat": "' . $js_time_format . '" }';
$args['data-timepicker'] = '{ "timeFormat": "' . $js_time_format . '" }';
}

return $this->text_date( $args );
Expand Down
2 changes: 1 addition & 1 deletion tests/test-cmb-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function test_text_time_field_after_value_update() {


$this->assertHTMLstringsAreEqual(
sprintf( '<input type="text" class="cmb2-timepicker text-time" name="field_test_field" id="field_test_field" value="%s" data-datepicker=\'{ "dateFormat": "mm&#39;/&#39;dd&#39;/&#39;yy" }\'/><span class="cmb2-metabox-description">This is a description</span>', $value ),
sprintf( '<input type="text" class="cmb2-timepicker text-time" name="field_test_field" id="field_test_field" value="%s" data-timepicker=\'{ "timeFormat": "hh:mm TT" }\'/><span class="cmb2-metabox-description">This is a description</span>', $value ),
$this->capture_render( array( $type, 'render' ) )
);

Expand Down

0 comments on commit b501ebe

Please sign in to comment.