Fixed an issue with clearing forms not correctly unsetting a value

This commit is contained in:
Thaum Rystra
2020-04-26 11:37:51 +02:00
parent 13cb9253c3
commit a2bae8d12a
6 changed files with 32 additions and 17 deletions

View File

@@ -1,7 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import SimpleSchema from 'simpl-schema';
import ChildSchema, { RefSchema } from '/imports/api/parenting/ChildSchema.js';
import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js';
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
import Creatures from '/imports/api/creature/Creatures.js';
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
import { softRemove } from '/imports/api/parenting/softRemove.js';
import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js';
@@ -150,7 +154,7 @@ const insertPropertyFromLibraryNode = new ValidatedMethod({
const updateProperty = new ValidatedMethod({
name: 'CreatureProperties.methods.update',
validate({_id, path, value}){
validate({_id, path}){
if (!_id) return false;
// We cannot change these fields with a simple update
switch (path[0]){
@@ -166,9 +170,15 @@ const updateProperty = new ValidatedMethod({
run({_id, path, value}) {
let property = CreatureProperties.findOne(_id);
assertPropertyEditPermission(property, this.userId);
CreatureProperties.update(_id, {
$set: {[path.join('.')]: value},
}, {
let pathString = path.join('.');
let modifier;
// unset empty values
if (value === null || value === undefined){
modifier = {$unset: {[pathString]: 1}};
} else {
modifier = {$set: {[pathString]: value}};
}
CreatureProperties.update(_id, modifier, {
selector: {type: property.type},
});
recomputeCreatures(property);

View File

@@ -1,3 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import SimpleSchema from 'simpl-schema';
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
@@ -56,7 +59,7 @@ const insertNode = new ValidatedMethod({
const updateLibraryNode = new ValidatedMethod({
name: 'LibraryNodes.methods.update',
validate({_id, path, value, ack}){
validate({_id, path}){
if (!_id) return false;
// We cannot change these fields with a simple update
switch (path[0]){
@@ -70,9 +73,15 @@ const updateLibraryNode = new ValidatedMethod({
run({_id, path, value}) {
let node = LibraryNodes.findOne(_id);
assertNodeEditPermission(node, this.userId);
return LibraryNodes.update(_id, {
$set: {[path.join('.')]: value},
}, {
let pathString = path.join('.');
let modifier;
// unset empty values
if (value === null || value === undefined){
modifier = {$unset: {[pathString]: 1}};
} else {
modifier = {$set: {[pathString]: value}};
}
return LibraryNodes.update(_id, modifier, {
selector: {type: node.type},
});
},
@@ -127,5 +136,4 @@ export {
pullFromLibraryNode,
pushToLibraryNode,
softRemoveLibraryNode,
libraryNodesToTree,
};

View File

@@ -109,7 +109,7 @@
:error-messages="errors.reset"
:menu-props="{auto: true, lazy: true}"
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['reset'], value: value || '', ack})"
@change="(value, ack) => $emit('change', {path: ['reset'], value, ack})"
/>
</form-section>
</form-sections>

View File

@@ -86,7 +86,7 @@
:error-messages="errors.reset"
:menu-props="{auto: true, lazy: true}"
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['reset'], value: value || '', ack})"
@change="(value, ack) => $emit('change', {path: ['reset'], value: value, ack})"
/>
</div>
</form-section>

View File

@@ -61,10 +61,9 @@
<proficiency-select
style="flex-basis: 300px;"
label="Base Proficiency"
clearable
:value="model.baseProficiency"
:error-messages="errors.baseProficiency"
@change="(value, ack) => {$emit('change', {path: ['baseProficiency'], value: value || '', ack}); log({value, ack})}"
@change="(value, ack) => {$emit('change', {path: ['baseProficiency'], value, ack})}"
/>
</div>
</form-section>
@@ -120,9 +119,6 @@
},
]
};},
methods: {
log: console.log,
},
};
</script>

View File

@@ -1,6 +1,7 @@
<template lang="html">
<smart-select
append-icon="arrow_drop_down"
clearable
class="ml-3"
v-bind="$attrs"
:menu-props="{transition: 'slide-y-transition', lazy: true}"
@@ -36,7 +37,7 @@
props: {
value: {
type: Number,
default: 1,
default: undefined,
},
},
data(){ return {