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 depends field not working for radio elements #11539

Merged

Conversation

jahvi
Copy link

@jahvi jahvi commented Oct 18, 2017

Fixes issue with configuration fields not toggling when <depends> is used on radio elements.

Description

Currently the <depends> field only works when used on elements of select type, this PR aims to replicate the same functionality for fields with radios type.

Fixed Issues (if relevant)

  1. <depends> field doesn't work in system.xml for "radios" fields #9360: field doesn't work in system.xml for "radios" fields

Manual testing scenarios

  1. Create field with type radios and corresponding field that dependant on one of its values as mentioned it <depends> field doesn't work in system.xml for "radios" fields #9360
  2. Navigate to backend and find configuration page with created field.
  3. Toggle radio options on and off, dependant field should hide/show as expected.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Oct 18, 2017

CLA assistant check
All committers have signed the CLA.

@jahvi
Copy link
Author

jahvi commented Oct 18, 2017

This is just an initial implementation of the fix the promote discussion, although it works I'm open to suggestions on best practices.

Copy link
Member

@osrecio osrecio left a comment

Choose a reason for hiding this comment

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

Extract line this.trackChange(null, idTo, elementsMap[idTo]); out of if/else and check test with codeStyle: Travis(289515174)

@@ -402,6 +402,17 @@ define([
);
this.trackChange(null, idTo, elementsMap[idTo]);
Copy link
Member

Choose a reason for hiding this comment

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

Extract this line out of if/else

'change',
this.trackChange.bindAsEventListener(this, idTo, elementsMap[idTo])
);
}
this.trackChange(null, idTo, elementsMap[idTo]);
Copy link
Member

Choose a reason for hiding this comment

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

Extract this line out of if/else

@jahvi jahvi force-pushed the fix/depends-not-working-radio-inputs branch from 1e7d9d4 to 5ac8f9f Compare October 20, 2017 14:30
@jahvi
Copy link
Author

jahvi commented Oct 20, 2017

@osrecio Thanks for the comments, I went ahead and made the recommended changes.

@osrecio
Copy link
Member

osrecio commented Oct 20, 2017

Looks ok for me

@magento-engcom-team magento-engcom-team added 2.2.x Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 7, 2017
@okorshenko okorshenko added this to the November 2017 milestone Nov 7, 2017
@omiroshnichenko omiroshnichenko self-requested a review November 17, 2017 06:15
values = valuesFrom[idFrom].values;
fromId = $(idFrom + values[0]);
radioFrom = $$('[name="' + fromId.name + '"]:checked');
isInArray = values.indexOf(radioFrom[0].value) != -1; //eslint-disable-line
Copy link
Contributor

@omiroshnichenko omiroshnichenko Nov 17, 2017

Choose a reason for hiding this comment

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

Add check on radioFrom.length > 0(in case when none is selected), make strict equality and remove eslint-disable-line

@jahvi jahvi force-pushed the fix/depends-not-working-radio-inputs branch 2 times, most recently from 707a952 to 427bdca Compare November 17, 2017 09:48
@jahvi
Copy link
Author

jahvi commented Nov 17, 2017

@omiroshnichenko Thanks for your input I just made the proposed changes.

// Check if radio button
values = elementsMap[idTo][idFrom].values;
fromId = $(idFrom + values[0]);
radioFrom = $$('[name="' + fromId.name + '"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

After testing was detected that additional check must be added

radioFrom = fromId ? $$('[name="' + fromId.name + '"]') : false;

} else {
values = valuesFrom[idFrom].values;
fromId = $(idFrom + values[0]);
radioFrom = $$('[name="' + fromId.name + '"]:checked');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same check here

radioFrom = fromId ? $$('[name="' + fromId.name + '"]:checked') : [];

@jahvi jahvi force-pushed the fix/depends-not-working-radio-inputs branch from 427bdca to 0031a1c Compare November 21, 2017 14:09
@jahvi
Copy link
Author

jahvi commented Nov 21, 2017

@omiroshnichenko Thanks just updated the PR with the changes

@okorshenko okorshenko merged commit 0031a1c into magento:2.2-develop Nov 22, 2017
@jahvi jahvi deleted the fix/depends-not-working-radio-inputs branch November 22, 2017 19:38
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 22, 2017
@WaPoNe
Copy link
Contributor

WaPoNe commented Feb 12, 2018

Great work @jahvi

@okorshenko this fix should be used also in 2.3-develop branch. Why don't I see it?

@okorshenko
Copy link
Contributor

It is on the way to 2.3-develop branch. Testing now

magento-engcom-team pushed a commit that referenced this pull request Apr 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants