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 Indeterminate State not Triggered from 'false' state #121

Merged
merged 5 commits into from
Apr 20, 2017
Merged

Fix Indeterminate State not Triggered from 'false' state #121

merged 5 commits into from
Apr 20, 2017

Conversation

vincent-leonardo
Copy link
Contributor

#76

Hi, after tracing the calls of indeterminate toggling I've found the source of this minor bug.
The problems happens with the default checkbox $formatters by angular.

The default checkbox formatters[0] on angular.js:24100

ctrl.$formatters.push(function(value) {
  return equals(value, trueValue);
});

So I did a quick hack to replace the default formatters in initMaybe @ bsSwitch.js

bsSwitch.js:153

controller.$formatters[0] = function(value) {
  if (value === undefined) {
    return value;
  }
  return angular.equals(value, getTrueValue());
}

Replaced default checkbox formatter to ignore comparing 'undefined'
value.
@frapontillo
Copy link
Owner

Awesome! Can you please add a test for the false-to-indeterminate switch? Try to cover all edge cases if possible. Thanks!

@vincent-leonardo
Copy link
Contributor Author

Done. I am not familiar with writing test case with karma (in fact it's the first time I've written one)
I don't use this library extensively, so I might not think of some edge cases.

Btw, I didn't realize indeterminate includes null value as well. Added it.

scope.$apply();
expect(element.hasClass(CONST.SWITCH_INDETERMINATE_CLASS)).toBeTruthy();
expect(element.hasClass(CONST.SWITCH_OFF_CLASS)).toBeFalsy();
expect(element.hasClass(CONST.SWITCH_ON_CLASS)).toBeTruthy();
Copy link
Owner

Choose a reason for hiding this comment

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

If it is indeterminate, how come the on class is set?

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 thought that's how your library behaves?
All your test codes were written that way.

@SiobhanBaynes
Copy link

Hi guys, Any idea when this will be merged?

@ygilliot
Copy link

ygilliot commented Mar 6, 2017

Since you ( @frapontillo ) validated, all checks have passed and branch has no conflicts, could you please merge to base?

I would prefer using "official" patched version than modifiying code file myself like a savage.
My thanks to @vincent-leonardo for resolving this bug.

@frapontillo
Copy link
Owner

@ygilliot I'm still not convinced by #121 (comment)

@frapontillo
Copy link
Owner

@vincent-leonardo can I have an update on this?

@vincent-leonardo
Copy link
Contributor Author

@frapontillo as I mentioned before, your test cases were written such that in indeterminate state the class will still be on. You can check your original test spec bsSwitchSpec.js:313

@frapontillo frapontillo merged commit 2376629 into frapontillo:develop Apr 20, 2017
@frapontillo
Copy link
Owner

Thanks @vincent-leonardo!

@vincent-leonardo
Copy link
Contributor Author

@frapontillo no problem, glad it helps.

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.

4 participants