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

[release-10.1] Fix form validation #4227

Conversation

EreMaijala
Copy link
Contributor

@EreMaijala EreMaijala commented Feb 3, 2025

The old validation mechanism was not compatible with Bootstrap 5 and didn't work properly with Bootstrap 3 either. The new uses the JS validation API. It is theme-independent and less intrusive with the caveat that the validation error messages are displayed in a browser-specific style.

TODO

  • Update changelog when merging (removal of broken vendor/validator.min.js; change in validation behavior, including deprecation of phoneNumberFormHandler in common.js)

The old validation mechanism was not compatible with Bootstrap 5 and didn't work properly with Bootstrap 3 either. The new uses the JS validation API. It is theme-independent and less intrusive with the caveat that the validation error messages are displayed in a browser-specific style.
@EreMaijala EreMaijala requested a review from demiankatz February 3, 2025 10:12
@EreMaijala EreMaijala changed the base branch from dev to release-10.1 February 3, 2025 10:12
@EreMaijala EreMaijala changed the title Fix form validation [release-10.1] Fix form validation Feb 3, 2025
@EreMaijala EreMaijala mentioned this pull request Feb 3, 2025
2 tasks
@demiankatz demiankatz added this to the 10.1.2 milestone Feb 3, 2025
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @EreMaijala, this is off to a good start. Looks like one test needs adjustment, though; I'm getting this failure in my environment:

There was 1 failure:

1) VuFindTest\Mink\RecordActionsTest::testSMS
Element not found: .modal .sms-error index 0
Failed asserting that null is of type object.

/usr/local/vufind/module/VuFind/src/VuFindTest/Integration/MinkTestCase.php:528
/usr/local/vufind/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php:705

Also, see below for a couple of other thoughts.

themes/bootstrap3/js/common.js Show resolved Hide resolved
function checkPhoneNumberValidity(ev) {
const field = ev.target;
if (field.id && field.type === 'tel' && field.dataset.validatorRegion) {
const valid = isPhoneNumberValid(field.value, field.dataset.validatorRegion);
Copy link
Member

Choose a reason for hiding this comment

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

If I'm following things correctly, I believe that isPhoneNumberValid is being exported by libphonenumber. It looks to me like we're using a version of libphonenumber from 2010 or so, which is probably outdated and inaccurate. It's out of scope for the current PR, but maybe when we update this for the 11.0 release, we should also introduce loading of libphonenumber via NPM (possibly using the lighter-weight libphonenumber-js) and make sure things work with the latest version. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That all would make sense, but I'd handle it separately. Not sure if libphonenumber-js supports usage without a module system, but any update would probably be better than the current one.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, definitely a separate issue, but worth doing before we forget about it. I can open a JIRA ticket if you think that would be the best next step.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would even make sense to evaluate all of our JS dependencies that are not currently installed via NPM and open tickets to update/replace all of them.

Copy link
Contributor Author

@EreMaijala EreMaijala Feb 3, 2025

Choose a reason for hiding this comment

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

Sounds good, please open a ticket about it!

Copy link
Member

Choose a reason for hiding this comment

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

Done: VUFIND-1751

@EreMaijala EreMaijala requested a review from demiankatz February 3, 2025 15:02
@EreMaijala
Copy link
Contributor Author

@demiankatz Test fixed. And the required attribute added to the sms number field.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @EreMaijala -- looks good to me now! A few tests were accidentally disabled by a recent commit, but I just went ahead and fixed that. Everything is passing on my end.

@demiankatz demiankatz merged commit 9f0985e into vufind-org:release-10.1 Feb 3, 2025
6 checks passed
@demiankatz demiankatz deleted the release-10.1-fix-form-validation branch February 3, 2025 15:46
EreMaijala added a commit to NatLibFi/NDL-VuFind2 that referenced this pull request Feb 7, 2025
The old validation mechanism was not compatible with Bootstrap 5 and didn't work properly with Bootstrap 3 either. The new uses the JS validation API. It is theme-independent and less intrusive with the caveat that the validation error messages are displayed in a browser-specific style.

(cherry picked from commit 9f0985e)
EreMaijala added a commit to NatLibFi/NDL-VuFind2 that referenced this pull request Feb 10, 2025
The old validation mechanism was not compatible with Bootstrap 5 and didn't work properly with Bootstrap 3 either. The new uses the JS validation API. It is theme-independent and less intrusive with the caveat that the validation error messages are displayed in a browser-specific style.

(cherry picked from commit 9f0985e)
(cherry picked from commit 8d3cc7f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants