2
0
mirror of https://github.com/frappe/books.git synced 2025-01-11 10:38:14 +00:00

fix: Add Numeric field types

- Int
- Float
- Currency
This commit is contained in:
Faris Ansari 2019-11-27 12:20:39 +05:30
parent 3e3235b814
commit 32b3793793
6 changed files with 46 additions and 2 deletions

View File

@ -68,8 +68,12 @@ export default {
this.$refs.input.focus(); this.$refs.input.focus();
}, },
triggerChange(value) { triggerChange(value) {
value = this.parse(value);
this.$emit('change', value); this.$emit('change', value);
}, },
parse(value) {
return value;
},
isNumeric(df) { isNumeric(df) {
return ['Int', 'Float', 'Currency'].includes(df.fieldtype); return ['Int', 'Float', 'Currency'].includes(df.fieldtype);
} }

View File

@ -0,0 +1,8 @@
<script>
import Float from './Float';
export default {
name: 'Currency',
extends: Float
};
</script>

View File

@ -6,7 +6,7 @@ export default {
extends: Link, extends: Link,
created() { created() {
this.targetWatcher = this.$watch(`doc.${this.df.references}`, function(newTarget, oldTarget) { this.targetWatcher = this.$watch(`doc.${this.df.references}`, function(newTarget, oldTarget) {
if (newTarget !== oldTarget) { if (oldTarget && newTarget !== oldTarget) {
this.triggerChange(''); this.triggerChange('');
} }
}); });

View File

@ -0,0 +1,13 @@
<script>
import Int from './Int';
export default {
name: 'Float',
extends: Int,
methods: {
parse(value) {
return parseFloat(value);
}
}
};
</script>

View File

@ -7,6 +7,9 @@ import AutoComplete from './AutoComplete';
import Check from './Check'; import Check from './Check';
import AttachImage from './AttachImage'; import AttachImage from './AttachImage';
import DynamicLink from './DynamicLink'; import DynamicLink from './DynamicLink';
import Int from './Int';
import Float from './Float';
import Currency from './Currency';
export default { export default {
name: 'FormControl', name: 'FormControl',
@ -20,7 +23,10 @@ export default {
AutoComplete, AutoComplete,
Check, Check,
AttachImage, AttachImage,
DynamicLink DynamicLink,
Int,
Float,
Currency
}; };
let { df } = this.$attrs; let { df } = this.$attrs;
return h(controls[df.fieldtype] || Data, { return h(controls[df.fieldtype] || Data, {

View File

@ -0,0 +1,13 @@
<script>
import Data from './Data';
export default {
name: 'Int',
extends: Data,
methods: {
parse(value) {
return parseInt(value, 10);
}
}
};
</script>