mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
feat: Check and DynamicLink control
This commit is contained in:
parent
84f5476909
commit
5d82625e23
33
src/components/Controls/Check.vue
Normal file
33
src/components/Controls/Check.vue
Normal 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>
|
26
src/components/Controls/DynamicLink.vue
Normal file
26
src/components/Controls/DynamicLink.vue
Normal 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>
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user