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

Fix: Empty any arrays if item in group is an object to remove from group #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/FormulateGrouping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script>
import { setId, shallowEqualObjects } from './libs/utils'
import { isObject, setId, shallowEqualObjects } from './libs/utils'

export default {
name: 'FormulateGrouping',
Expand Down Expand Up @@ -118,6 +118,13 @@ export default {
removeItem (index) {
if (Array.isArray(this.context.model) && this.context.model.length > this.context.minimum) {
// In this context we actually have data
if (isObject(this.context.model[index])) {
Object.keys(this.context.model[index]).forEach(key => {
if (Array.isArray(this.context.model[index][key])) {
this.context.model[index][key].splice(0, this.context.model[index][key].length)
}
})
}
this.context.model.splice(index, 1)
} else if (this.items.length > this.context.minimum) {
// In this context the fields have never been touched (not "dirty")
Expand Down
8 changes: 8 additions & 0 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,11 @@ export function isEmpty (value) {
)
)
}

/**
* Determines if a given value is an object and not an array or null
* @param {any} value
*/
export function isObject(value) {
return value != null && typeof value === 'object' && Array.isArray(value) === false;
}