-
Notifications
You must be signed in to change notification settings - Fork 15
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
Object formatting #34
Comments
Okay, I've been able to reproduce this: https://codesandbox.io/p/sandbox/wizardly-yalow-g5qlym?file=%2Fsrc%2Fstyles.css%3A3%2C18 The problem is due to a |
Righto, v1.5.3 out now. Please let me know if it fixes your case and I'll close the issue. Thanks for bringing it to my attention |
You can set the default value prop: I guess I could make the
You can restrict the type selection list: Thanks for the suggestion. I've made an issue to address this: #35 It should be fairly straightforward, I'll try and update it in the next couple of days. |
Original issue solved |
Yes, adding the ability for the default value and restrictTypeSelection props to take a function would address both issues. Appreciate your support! |
|
Okay, @jkk4999, you can try v1.6.0 now, with your requested feature. You should be able to achieve what you want by specifying: // Create empty objects at the root level, strings elsewhere:
defaultValue={({ level }) => {
if (level === 0) return {}
return 'New Value'
}},
// Prevent changing values to objects or arrays:
restrictTypeSelection={['string', 'number', 'boolean', 'null']} There's an example of something similar in the Demo -- if you select "Client List" data set and add a new item at the root level, you'll get a pre-filled structured object, but just plain strings elsewhere. Thanks for the suggestion -- not sure why I hadn't done that already -- you could already specify functions for pretty much all other values. ;) |
That works...thanks! In my use case, I need to restrict the values of child nodes to 'string', 'number' or 'boolean'. To that end, I make use of the onEdit function and inspect the value of newValue prop. Per your documentation, if you return false or a string, the internal data state won't actually be updated. However, it seems like it is. If I enter a value that doesn't pass my validation rule I'm returning a string. I see the error message but the control displays the entered value. My expectation would be the control discards the entered value and displays the previous value in state. In a related issue, the error message persists for a few seconds. It would be preferable that the error message is displayed until such time as the error is resolved. For reference, here is the code: onEdit={({ newData, currentData, newValue, currentValue, name, path }) => {
|
Oh, that's a good point. I should be able to change this pretty easily to only update the internal state if the update function doesn't return an error. The only tricky thing is that the update function can take a significant amount of time (if it's updating to an API), but I want the UI update to be instant. I guess we could have the UI update, but then switch back to the original value if the update function subsequently fails (and shows the error). Would that be okay you think? |
Is restricting the available types in |
I'll have to think about this/play around with it. In light of your other comment, if we don't actually update the internal state on error, then it won't actually be in an illegal state. This is how it works for other errors, such as invalid JSON -- the internal state never gets updated, so the error message just shows for a certain time. |
If the state is not updated, then it's fine to temporarily display the
error message as it currently works.
…On Wed, Feb 28, 2024 at 4:50 PM Carl Smith ***@***.***> wrote:
In a related issue, the error message persists for a few seconds. It would
be preferable that the error message is displayed until such time as the
error is resolved.
I'll have to think about this/play around with it. In light of your other
comment, if we don't actually update the internal state on error, then it
won't actually be in an illegal state. This is how it works for other
errors, such as invalid JSON -- the internal state never gets updated, so
the error message just shows for a certain time.
—
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOFAIZX3KN6A4H6SXWCWHBDYVZIJVAVCNFSM6AAAAABDY52OFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRZHE3TSMBUHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Perfect. Thanks so much for your efforts! |
Hi,
When adding an object, the closing parentheses are indented. Thanks for your contribution!
The text was updated successfully, but these errors were encountered: