Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Form: Convert HTML5 date input to text input + jQuery Datepicker #7890

Merged

Conversation

rclations
Copy link
Contributor

@rclations rclations commented Sep 28, 2017

There's some issues popping up in review (#7885, #7887, #7888, #7889) that appear to step from spotty cross-browser support for the HTML5 date input field.

Some information about this can be found here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Handling_browser_support

jQuery datepicker is already being used for fallback support in legacy browsers (added in #7819). This PR converts the default display from HTML5 date input to use a text input + jQuery datepicker always.

Changes proposed in this Pull Request:

  • Switch contact form HTML5 date input to a text input with date class.
  • Remove conditional logic so that jQuery datepicker is always used for text inputs with class date (instead of only as a fallback for browsers that don't support the date input type).
  • Fixes the duplicate year issue reported in Contact Form / Date Picker: duplicate year displayed after picking date #7887 (Apparently jQuery uses yy to denote a 4-digit year)
  • tabify the css file
  • minor css updates for cross-browser display support

Testing instructions:

  • Try creating a form containing a date field using the visual editor.
  • Visit the front end and try interacting with the date field. This should initiate a styled jQuery datepicker. Make sure that the styling appears as you would expect.

Notes:

@dereksmart dereksmart added [Feature] Contact Form [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Type] Bug When a feature is broken and / or not performing as intended labels Sep 28, 2017
if ( 'function' === typeof $.fn.datepicker && 'text' === datefield[0].type ) {
datefield.datepicker( { dateFormat : 'yyyy-mm-dd' } );
}
$( '.contact-form input.date' ).datepicker( { dateFormat : 'yy-mm-dd' } );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we find a way to scope this better? These are pretty generic classes and it's technically possible (yet unlikely) that there will be another form with the same classes on the same page in a sidebar/widget whatever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the class to jp-contact-form-date.
The input class is pulled from the shortcode, so I added a check in render() to override the default for date type fields.

This could be resolved more elegantly in the future via #5876

@zinigor
Copy link
Member

zinigor commented Sep 28, 2017

Thanks for fixing it! Sticking with datepicker for now seems like the best idea. I have added one commit that will use the current site's locale to properly translate and choose the correct date format.

@jeherve jeherve added this to the 5.4 milestone Sep 29, 2017
$r .= "\t</div>\n";

wp_enqueue_script( 'grunion-frontend', plugins_url( 'js/grunion-frontend.js', __FILE__ ), array( 'jquery', 'jquery-ui-datepicker' ) );
wp_enqueue_style( 'jp-jquery-ui-datepicker', plugins_url( 'css/jquery-ui-datepicker.css', __FILE__ ), array( 'dashicons' ), '1.0' );

// Using Core's built-in datepicker localization routine
wp_localize_jquery_ui_datepicker();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zinigor This causes the date to look like this when chosen:

screen shot 2017-09-29 at 10 25 25 am

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me what date format you have set in your WordPress settings? This is what it uses if you don't set anything else.

Copy link
Member

@dereksmart dereksmart Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zinigor it's a custom date format for some reason. I don't remember setting it

wp> get_option( 'date_format' );
string(15) "j \d\e F \d\e Y"

@dereksmart dereksmart dismissed their stale review September 29, 2017 16:55

This changes correctly as I set the option, so it looks like it's working properly

Copy link
Member

@dereksmart dereksmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@dereksmart dereksmart added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 29, 2017
@dereksmart dereksmart merged commit 8784541 into Automattic:master Sep 29, 2017
@dereksmart dereksmart removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 29, 2017
dereksmart pushed a commit that referenced this pull request Sep 29, 2017
…ker (#7890)

* convert HTML5 date into to text field + jQuery datepicker

* fixing jquery datepicker year format
jQuery uses yy for 4 digit year - see http://api.jqueryui.com/datepicker/\#utility-formatDate

* removing date input field styles

* updating contact form editor view to not use HTML5 date input

* Contact Form: Update date input class name to be more specific
Check input type on output and update classname there (vs. in shortcode)

* Added Core's native method of localizing jQuery datepicker.
@dereksmart
Copy link
Member

merged to 5.4 c3a1807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Pri] BLOCKER [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants