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

Cleave updates #10

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion dist/vfg.js

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions src/fields/optional/fieldCleave.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<script>
import abstractField from "../abstractField";
import { defaults, isString } from "lodash";
import { defaults, isString, isNil } from "lodash";

export default {
mixins: [abstractField],
Expand Down Expand Up @@ -50,6 +50,13 @@ export default {
this.$watch("cleave.properties.result", () => {
this.value = this.cleave.properties.result;
});

if (!(this.isNilOrBlank(this.value) && this.isNilOrBlank(this.cleave.properties.result)) && this.value !== this.cleave.properties.result) {
// We only set if one of the values is not null, undefined or blank but not both.
// That means we either have a new value or we are setting to "" to delete any this.value we had before.
this.value = this.cleave.properties.result;
}

} else {
this.$el.addEventListener("input", this.inputChange);
}
Expand All @@ -58,8 +65,20 @@ export default {
}
});
},

watch: {
value(formattedValue) {
if (this.cleave) {
this.$nextTick(() => {
// nextTick here is needed to allow Cleave to render the correct formatted value to be saved
this.cleave.setRawValue(formattedValue);
paulogiacomelli marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
},
methods: {
isNilOrBlank(value) {
return isNil(value) || value === "";
},
inputChange() {
let newValue = this.$el.value;

Expand Down