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(MdField): fix the character counter not reseting when reseting the form #2213

Merged
merged 2 commits into from
May 27, 2020
Merged
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
6 changes: 4 additions & 2 deletions docs/app/pages/Components/Input/examples/Counters.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<form>
<md-field>
<label>Counter</label>
<md-input v-model="regular" md-counter="30"></md-input>
Expand All @@ -24,7 +24,9 @@
<label>Textarea</label>
<md-textarea v-model="textarea" md-counter="80"></md-textarea>
</md-field>
</div>

<md-button class="md-raised" type="reset">RESET</md-button>
</form>
</template>

<script>
Expand Down
21 changes: 21 additions & 0 deletions src/components/MdField/MdFieldMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ export default {
}
}
},
setFormResetListener () {
if (!this.$el.form) {
return
}
const parentForm = this.$el.form
parentForm.addEventListener('reset', this.onParentFormReset)
},
removeFormResetListener () {
if (!this.$el.form) {
return
}
const parentForm = this.$el.form
parentForm.removeEventListener('reset', this.onParentFormReset)
},
onParentFormReset () {
this.clearField()
},
setFieldValue () {
this.MdField.value = this.model
},
Expand Down Expand Up @@ -130,5 +147,9 @@ export default {
},
mounted () {
this.setLabelFor()
this.setFormResetListener()
},
beforeDestroy () {
this.removeFormResetListener()
}
}