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

Dynamic Form: boolean fields related fixes #4586

Merged
merged 4 commits into from
Mar 3, 2020
Merged

Conversation

arikfr
Copy link
Member

@arikfr arikfr commented Jan 23, 2020

What type of PR is this? (check all applicable)

  • Bug Fix

Description

Two fixes:

  • When a boolean field had default value of false we would set false as the default value instead of the string value, which fails prop types.
  • When an extra boolean field had default value of true it would make the extra fields section to be open.

Copy link
Collaborator

@kravets-levko kravets-levko left a comment

Choose a reason for hiding this comment

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

I don't have that deep knowledge in how DynamicForm works, so may need to clarify some things.

@@ -9,7 +9,7 @@ function orderedInputs(properties, order, targetOptions) {
name: key,
title: properties[key].title,
type: properties[key].type,
placeholder: properties[key].default && properties[key].default.toString(),
placeholder: (properties[key].default === false || properties[key].default) && properties[key].default.toString(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand this correctly, it should add placeholder for fields with default value false, right? If yes - isn't it better to use something like isNil(properties[key].default && toString(properties[key].default)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand your question, but basically if a default value exists, it takes the default value and converts it into a string. Previously the check would miss default value of false as it doesn't pass the check -- this change fixes this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My question is about (properties[key].default === false || properties[key].default). I understand why there's a check for properties[key].default === false, but second part will not match, say, number 0 (it's evaluated to false), so fields with default numeric value 0 will not have placeholder as well. So I suggested to replace that entire thing with isNil which basically is a check for value === undefined || value === null - so all fields that have defined default value will have a placeholder. There is also a case when default value is empty string, but in this case it will receive an empty string placeholder - the same as with current code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if numeric fields with default 0 should have a placeholder at all, so maybe it's expected behaviour and my comment does not make any sense 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right the nil check will work better. I'll fix this.

As for the question about numbers, I'm not sure. You're probably right but I would rather not make tto many changes here as I don't fully understand the code. 😬

Copy link
Member

Choose a reason for hiding this comment

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

Looking again at this, from what I remember this is just supposed to make any default value a placeholder in the inputs. It looks like Lodash's toString does exactly that (converts all to String, except null or undefined).

Having only this lodash function should make it a bit more readable (at list in this line 😅).

Copy link
Member Author

Choose a reason for hiding this comment

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

_.toString returns an empty string for null/undefined.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but it seemed ok to have placeholder: "" in such cases as the result should remain the same 🙂

@arikfr arikfr merged commit 78201c6 into master Mar 3, 2020
@arikfr arikfr deleted the fix-dynamic-form-bool branch March 3, 2020 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants