Skip to content

Commit

Permalink
feat(form): support union key for v-for
Browse files Browse the repository at this point in the history
  • Loading branch information
dolymood committed Feb 16, 2020
1 parent c63fb3d commit 74c791b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/form/form-group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<slot>
<cube-form-item
v-for="(field, index) in fields"
:key="index"
:key="field.key || index"
:field="field"
/>
</slot>
Expand Down
12 changes: 9 additions & 3 deletions src/components/form/form.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<form ref="form" class="cube-form" :class="formClass" :action="action" @submit="submitHandler" @reset="resetHandler">
<slot>
<cube-form-group v-for="(group, index) in groups" :fields="group.fields" :legend="group.legend" :key="index" />
<cube-form-group
v-for="(group, index) in groups"
:fields="group.fields"
:legend="group.legend"
:key="group.key || index" />
</slot>
</form>
</template>
Expand Down Expand Up @@ -296,12 +300,14 @@
},
addField(fieldComponent) {
this.fields.push(fieldComponent)
this.setValidity(fieldComponent.fieldValue.modelKey)
const modelKey = fieldComponent.fieldValue.modelKey
modelKey && this.setValidity(modelKey)
},
destroyField(fieldComponent) {
const i = this.fields.indexOf(fieldComponent)
this.fields.splice(i, 1)
this.setValidity(fieldComponent.fieldValue.modelKey)
const modelKey = fieldComponent.fieldValue.modelKey
modelKey && this.setValidity(modelKey)
}
},
beforeDestroy() {
Expand Down

0 comments on commit 74c791b

Please sign in to comment.