-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feature/fix enum empty bug #1163
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
Feature/fix enum empty bug #1163
Conversation
…efault value is 0 or false or ''.
|
@huhuaaa Can you explain what issue you are solving? When the default value is 0 or false or "", what do you expect the dropdown to look like? When the default value is "" or false or "" for me, it looks like this (playground link): |
|
Yes, i use "typeof default === 'undefined'" to check the default value. |
|
Why would we not want to have an empty option when the default is 0 or false or ''? |
|
Yes, when the default is 0 or false or '' , we need an option. But i think an empty option is not the best one. And there's another bug here,i set enum = [0,1] and enumNames = ['zero', 'one'] , the empty option also showing. This result is not expected. |
|
Oh, I see, so this is solving #1177 |
|
@huhuaaa Can you add some tests for this? |
|
OK |
|
I had commited the tests. |
epicfaace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests -- can you add that additional test I mentioned? Additionally, rather than making a separate file, I think you should add those tests in this file: https://github.com/mozilla-services/react-jsonschema-form/blob/master/test/NumberField_test.js#L244
test/enum_test.js
Outdated
| expect(options[0].innerHTML).eql("0"); | ||
| }); | ||
|
|
||
| it("should render a select element and it's first option is 'false', if set the enum and the default value is false.", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test in which the default value is '', and then it shouldn't render two empty options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestions, i have adjusted it.


Fixed the bug. The selector have an empty option, when use enum and the default value is 0 or false or ''.
Reasons for making this change
[Please describe them here]
Fixed the bug. The selector have an empty option, when use enum and the default value is 0 or false or ''.
Checklist
npm run cs-formaton my branch to conform my code to prettier coding style