Automattic / WP-Job-Manager

Manage job listings from the WordPress admin panel, and allow users to post jobs directly to your site.
https://wpjobmanager.com
GNU General Public License v3.0
895 stars 366 forks source link

Fix for the hidden and displayed datepicker fields not holding the cu… #2766

Closed btsdev closed 3 months ago

btsdev commented 4 months ago

Fix for the hidden and displayed datepicker fields not holding the current values for _job_expires in datepicker.js.

Fixes #2739

Changes Proposed in this Pull Request

Testing Instructions

Release Notes

btsdev commented 4 months ago

Not sure how important it was to ensure that the names I added were camelCase (as I see a bit of mixing of naming styles: snake_case and "$snake_case" in some places. However, I won't touch any of that code as that would be out of scope for the purpose of this PR).

The need to add the dateFormatFunction function itself does feel a bit odd as it feels a bit redundant with jquery-ui-datepicker's functionality, but getting the day of the month correct meant I needed to ensure that it was incremented by 1 and also ensure it was always two digits (e.g. "2" should be "02") for some reason (e.g. "2024-02-4" gets converted to "February 4, 2024", but "2024-02-04" gets converted to "February 3, 2024", going back a day for some reason).

The fix to the field values now occurs at the end of the initializeDatepicker function (I initially was applying this at the end of the ready function block, but that seemed inaccurate).

Note that at the end of initializeDatepicker I'm using $target[0].getAttribute("value") rather than $target.val(). I ran into issues where the former code gave me the value, but the latter gave me nothing. I've no idea why this bug was happening, but at least this work around does the job.

I've tested my changes on my client's WP install to ensure this fix is still working.

(also note the force pushes were just to amend some typos in my commit messages)

mikeyarce commented 4 months ago

Hi @btsdev - I had a look at this issue as well and am proposing a more simple solution which you can see here: https://github.com/Automattic/WP-Job-Manager/pull/2779

Let me know what you think and if you're able to test it at all.

mikeyarce commented 3 months ago

Closing this as this other PR fixes it https://github.com/Automattic/WP-Job-Manager/pull/2779