Skip to content
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;
}