2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00

feat: Check and DynamicLink control

This commit is contained in:
Faris Ansari 2019-11-19 23:25:28 +05:30
parent 84f5476909
commit 5d82625e23
3 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,33 @@
<template>
<div>
<label
class="flex items-center"
>
<input
ref="input"
type="checkbox"
:class="inputClasses"
:checked="value"
:readonly="isReadOnly"
@change="e => triggerChange(+e.target.checked)"
@focus="e => $emit('focus', e)"
/>
<div class="ml-3 text-gray-900 text-sm">
{{ df.label }}
</div>
</label>
</div>
</template>
<script>
import Base from './Base';
export default {
name: 'Check',
extends: Base,
computed: {
inputClasses() {
return [this.inputClass];
}
}
};
</script>

View File

@ -0,0 +1,26 @@
<script>
import Link from './Link';
export default {
name: 'DynamicLink',
props: ['target'],
extends: Link,
created() {
this.targetWatcher = this.$watch(`doc.${this.df.references}`, function(newTarget, oldTarget) {
if (newTarget !== oldTarget) {
this.triggerChange('');
}
});
},
destroyed() {
this.targetWatcher();
},
methods: {
getTarget() {
if (!this.doc) {
throw new Error('You must provide `doc` for DynamicLink to work.');
}
return this.doc[this.df.references];
}
}
};
</script>

View File

@ -4,6 +4,9 @@ import Link from './Link';
import Date from './Date';
import Table from './Table';
import AutoComplete from './AutoComplete';
import Check from './Check';
import AttachImage from './AttachImage';
import DynamicLink from './DynamicLink';
export default {
name: 'FormControl',
@ -14,7 +17,10 @@ export default {
Link,
Date,
Table,
AutoComplete
AutoComplete,
Check,
AttachImage,
DynamicLink
};
let { df } = this.$attrs;
return h(controls[df.fieldtype] || Data, {
@ -26,6 +32,9 @@ export default {
methods: {
focus() {
this.$refs.control.focus();
},
getInput() {
return this.$refs.control.$refs.input;
}
}
};