-
-
Notifications
You must be signed in to change notification settings - Fork 239
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 initialValue check #164
Conversation
Could make a reproduction? Or at least share schema and/or used form? |
@@ -44,7 +44,7 @@ export default function connectField (component, { | |||
return; | |||
} | |||
|
|||
if (props.value === undefined && props.required) { | |||
if (!props.value && props.required) { |
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.
This should be changed - if a field has a falsy value, like false
and initialValue
equal to true
, it will cause a problem. Empty string is caused by ensureValue: true
- this flag is used to avoid undefined
in HTML inputs.
I'd suggest
- if (props.value === undefined && props.required) {
+ if (props.required && (this.options.ensureValue ? props.value === '' : props.value === undefined)) {
I'm using graphql, so there is no default value in schema. Component looks like following: <AutoForm
ref={ ref => formRef = ref }
schema={ bridge }
onSubmit={ this.onSubmit }>
<SelectField
name='adapterset'
allowedValues={ adaptersetOptions }
transform={ getEnumOption.bind(this, sampleEnums.adapterset) }
initialValue='ILLUMINA_GENERIC'
required={ true } />
</AutoForm> Schema: input SampleInput {
adapterset: String!
} Your suggestion looks good, I'll rewrite commit. |
|
38c7dd5
to
ba44b80
Compare
I've rewritten commit. |
BTW graphql intergation works quite good with form! Thank you for this.) |
I've tried to get rid of it and failed few times so far. If you could handle it or help to do so - I'd love to help. |
Currently there is no way set default value for SelectField, because its value by default is
''
(empty string) which is not equal toundefined
.