-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Nested Lists] ListType: reset list when no value is submitted, cast objects with nu… #3776
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
base: nested-lists
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,17 +185,19 @@ list.prototype.updateItem = function (item, data, files, callback) { | |
|
||
var field = this; | ||
var values = this.getValueFromData(data); | ||
// Don't update the value when it is undefined | ||
if (values === undefined) { | ||
return utils.defer(callback); | ||
} | ||
// Reset the value when null or an empty string is provided | ||
if (values === null || values === '') { | ||
// Reset the value when no value or null or an empty string is provided | ||
if (values === undefined || values === null || values === '') { | ||
values = []; | ||
} | ||
// Wrap non-array values in an array | ||
if (!Array.isArray(values)) { | ||
values = [values]; | ||
if (typeof values === 'object' && values[0] !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, |
||
// Cast an object with numeric keys to an array | ||
values.length = Object.getOwnPropertyNames(values).length; | ||
values = Array.prototype.slice.call(values); | ||
} else { | ||
// Wrap non-array values in an array | ||
values = [values]; | ||
} | ||
} | ||
// NOTE - this method will overwrite the entire array, which is less specific | ||
// than it could be. Concurrent saves could lead to race conditions, but we | ||
|
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 is a definite change in semantics, I think it would be better to leave the
undefined
case as-is…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.
Sorry, I was cheating here to fix two bugs at once.
With the
undefined
case as it is there is no way to empty out the list. The last item will never be deleted because an empty list won't be submitted at all. TextArray, DateArray, and NumberArray all treat undefined the way I've done here.