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

Fix JQuery Validation for radios #17937

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Jul 24, 2020

Overview

This fixes the jQuery validation for radio html objects by ensuring that the required attribute is properly set on radio html objects and that the error message is correctly placed

Before

  1. Create a profile that includes the gender field as a required field
  2. Set that profile to be used on a contribution page
  3. Navigate to the live contribution page
  4. Open up the console and enter in CRM.$('#Main').valid();
  5. Note that in the console you get a message about it being invalid but note there is no visual display that the gender is a required field

After

Repeat Steps 1-4 as above but in step 5 you should find that for the radio field there is a new message that it is a required field sitting next to the radios

ping @demeritcowboy @mattwire @colemanw

@civibot
Copy link

civibot bot commented Jul 24, 2020

(Standard links)

@civibot civibot bot added the master label Jul 24, 2020
@seamuslee001 seamuslee001 changed the title Radio jquery require WIP: Fix JQuery Validation for radios Jul 24, 2020
@seamuslee001 seamuslee001 force-pushed the radio_jquery_require branch from 6d3ef34 to 00e7a4a Compare July 25, 2020 09:37
Fix layout of required radio message
@seamuslee001 seamuslee001 force-pushed the radio_jquery_require branch from 00e7a4a to dd28351 Compare July 25, 2020 20:28
@seamuslee001 seamuslee001 changed the title WIP: Fix JQuery Validation for radios Fix JQuery Validation for radios Jul 25, 2020
@@ -366,6 +366,9 @@ public function &add(
$type, $name, $label = '',
$attributes = '', $required = FALSE, $extra = NULL
) {
if ($type === 'radio') {
CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_Form::addRadio');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this in because at the moment CRM_Core_Form::add 's function declaration makes no sense for radios better to use the addRadio function instead

@demeritcowboy
Copy link
Contributor

Tested and overall this works.

I was wondering if it's just radios that need this, so I also checked checkboxes. It works but behaves differently with stripe vs not stripe, but I'm not sure if that's a flaw in jquery validate? With stripe (which I assume is using jquery validate), you have to check all the checkboxes. With not-stripe, required just means you have to pick at least one checkbox, which matches what I'd expect.

@eileenmcnaughton
Copy link
Contributor

this is very form layer so I think it's OK without test.

My take on this is that it is mergeable but that perhaps there is more that should be considered. Adding merge-ready to give @seamuslee001 & @demeritcowboy space to loop back in on the last comment

@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label Aug 2, 2020
@mattwire
Copy link
Contributor

mattwire commented Aug 2, 2020

@demeritcowboy Stripe currently loads in some overrides for jquery validate to make it work properly without modifying CiviCRM core.

This should be tested using the following in the browser console (without stripe loaded):
For testing you can do in the browser console on a contribution page:
var validator = CRM.$('#Main').validate();
validator.settings - to show the settings that are loaded for the page.
CRM.$('#Main').valid(); to check if the form is "valid" - returns true/false.

I may well need to update the Stripe code to remove some of the overrides once this is merged. That's a good thing because we'll have more consistency and less need to hack around stuff :-)

@eileenmcnaughton
Copy link
Contributor

@mattwire does this mean we should remove merge-ready?

@mattwire
Copy link
Contributor

mattwire commented Aug 2, 2020

I'd like either @seamuslee001 or @demeritcowboy to do a quick test with the commands I've put up but I'm happy for this to be "merge ready" as if it does trigger any issues they are likely to be less than what there was before and we can work through to resolve those too. When I started looking at the jquery validation stuff we were in a pretty bad place with Civi, thanks to that initial work and then the work that @seamuslee001 has been doing we're really getting somewhere

@demeritcowboy
Copy link
Contributor

Ok thanks that probably explains the stripe part. I'm good.

@mattwire
Copy link
Contributor

mattwire commented Aug 3, 2020

Merging based on discussion and @demeritcowboy

@mattwire mattwire merged commit d155cca into civicrm:master Aug 3, 2020
@eileenmcnaughton eileenmcnaughton deleted the radio_jquery_require branch August 3, 2020 23:48
@eileenmcnaughton
Copy link
Contributor

Just noting this has caused an (unreleased) regression - https://lab.civicrm.org/dev/core/-/issues/1928#note_41814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections ok-without-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants