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

Core: fix validation for input type="date" #2360

Merged
merged 3 commits into from May 6, 2022

Conversation

tyomitch
Copy link
Contributor

@tyomitch tyomitch commented Nov 18, 2020

No tests here, because none are possible with methods from localization/ (quoting https://github.com/jquery-validation/jquery-validation/blob/master/test/methods.js#L186 : "need to figure out how to test localized methods")

Fixes #2359

@micschk
Copy link

@micschk micschk commented Sep 11, 2021

Would be nice if this could be merged (assuming it indeed fixes date inputs).

@staabm
Copy link
Member

@staabm staabm commented Sep 11, 2021

Could you verify wether it fixes the mentioned problem and also add a unit test?

@nenadvicentic
Copy link

@nenadvicentic nenadvicentic commented Dec 7, 2021

Hi,

I tested this change on de culture and it seems to work fine.

Overwritten original rules[method] = true line with rules[type === "date" ? "dateISO" : method] = true; and input type=date client side validation started to work.

Is there any elegant way to monkey-patch this until the fix is officially released?

@staabm
Copy link
Member

@staabm staabm commented Dec 7, 2021

In case we get a unit test for the expected behavior which passes with thxis change, we could merge the PR

@nenadvicentic
Copy link

@nenadvicentic nenadvicentic commented Dec 7, 2021

In case we get a unit test for the expected behavior which passes with thxis change, we could merge the PR

I am not familiar with jQuery source or tests, so not sure if I personally can help. My intuition tells me, unit tests where for input type=date jquery-validation method $(element).rules() returns { dateISO: true} instead of current { date: true } would be sufficeint.

@staabm Any tip where this test can be added/implemented?

@nenadvicentic
Copy link

@nenadvicentic nenadvicentic commented Dec 7, 2021

@tyomitch, @staabm Boys, there example of your unit-test:

QUnit.test( "rules() - returns dateISO for input type=date", function( assert ) {
	$( "#rangesMinDateInvalid" ).validate();
	assert.deepEqual( $( "#minDateInvalid" ).rules(), { dateISO: true, min: "2012-12-21" } );
} );

It can be added to /test/rules.js file. I used existing input type=date element in index.html - #minDateInvalid, which also contains min rule.

@tyomitch , @staabm How should we proceed with this?

@tyomitch
Copy link
Contributor Author

@tyomitch tyomitch commented Dec 9, 2021

@nenadvicentic done, updated the patch with your test case.

The scenario which should be tested is that a localized date input passes validation; but perhaps @staabm can accept this as a passable approximation.

@nenadvicentic
Copy link

@nenadvicentic nenadvicentic commented Dec 10, 2021

The scenario which should be tested is that a localized date input passes validation; but perhaps @staabm can accept this as a passable approximation.

By specification value property of input type=date is always formatted as ISO8601 date yyyy-mm-dd regardless of localized formatting displayed by browser. Details can be found in Mozilla developer network article.

So test that dateISO validation is picked for <input type="date"> is enough.

Note: The displayed date format will differ from the actual value — the displayed date is formatted based on the locale of the user's browser, but the parsed value is always formatted yyyy-mm-dd.

@tyomitch , @staabm : more I am thinking about this scenario, I am wondering if there is a need for validation at all in this case, since browser ensures that, if value is there, it has to be in correct format.

@github-actions
Copy link

@github-actions github-actions bot commented May 6, 2022

This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automatically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)

@github-actions github-actions bot added the stale label May 6, 2022
@tyomitch
Copy link
Contributor Author

@tyomitch tyomitch commented May 6, 2022

I think this is wrong, and the problem still persists.

@bytestream bytestream merged commit 350f6ae into jquery-validation:master May 6, 2022
1 check passed
@bytestream bytestream removed the stale label May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants