Fix char values issue (#13946)

* Fix selection highlight in avatar editor

* Add validation for Fix Character Values fields
This commit is contained in:
Vanathi G
2022-04-30 02:27:32 +05:30
committed by GitHub
parent 22b5a5e6f2
commit 7a94b031e0

View File

@@ -143,12 +143,11 @@ export default {
}, },
methods: { methods: {
close () { close () {
this.validateInputs();
this.$root.$emit('bv::hide::modal', 'restore'); this.$root.$emit('bv::hide::modal', 'restore');
}, },
restore () { restore () {
if (this.restoreValues.stats.lvl < 1) { if (!this.validateInputs()) {
// @TODO:
// Notification.error(env.t('invalidLevel'), true);
return; return;
} }
@@ -175,6 +174,35 @@ export default {
this.$store.dispatch('user:set', settings); this.$store.dispatch('user:set', settings);
this.$root.$emit('bv::hide::modal', 'restore'); this.$root.$emit('bv::hide::modal', 'restore');
}, },
validateInputs () {
const canRestore = ['hp', 'exp', 'gp', 'mp'];
let valid = true;
for (const stat of canRestore) {
if (this.restoreValues.stats[stat] === '') {
this.restoreValues.stats[stat] = this.user.stats[stat];
valid = false;
}
}
const inputLevel = Number(this.restoreValues.stats.lvl);
if (this.restoreValues.stats.lvl === ''
|| !Number.isInteger(inputLevel)
|| inputLevel < 1) {
this.restoreValues.stats.lvl = this.user.stats.lvl;
valid = false;
}
const inputStreak = Number(this.restoreValues.achievements.streak);
if (this.restoreValues.achievements.streak === ''
|| !Number.isInteger(inputStreak)
|| inputStreak < 0) {
this.restoreValues.achievements.streak = this.user.achievements.streak;
valid = false;
}
return valid;
},
}, },
}; };
</script> </script>