|
| 1 | +<template> |
| 2 | + <default-field :field="field" :errors="errors" :full-width-content="true"> |
| 3 | + <template slot="field"> |
| 4 | + <div class="flex mb-4"> |
| 5 | + <div class="w-1/2 m-3"> |
| 6 | + <label :for="field.name" class="block mb-1">Code</label> |
| 7 | + </div> |
| 8 | + |
| 9 | + <div class="w-1/2 m-3"> |
| 10 | + <label class="block mb-1">Preview</label> |
| 11 | + </div> |
| 12 | + </div> |
| 13 | + <div class="flex mb-4"> |
| 14 | + <div class="w-1/2 m-3"> |
| 15 | + <textarea |
| 16 | + :id="field.name" |
| 17 | + type="text" |
| 18 | + class="w-full form-input form-input-bordered" |
| 19 | + :class="errorClasses" |
| 20 | + :placeholder="field.name" |
| 21 | + v-model="value" |
| 22 | + v-bind="extraAttributes" |
| 23 | + /> |
| 24 | + </div> |
| 25 | + |
| 26 | + <div class="w-1/2 m-3"> |
| 27 | + <preview-html |
| 28 | + class="resize-y" |
| 29 | + :fieldNameToPreview="field.name" |
| 30 | + :src="value" |
| 31 | + :styles="field.styles" |
| 32 | + :template="field.template" |
| 33 | + /> |
| 34 | + |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + |
| 38 | + </template> |
| 39 | + </default-field> |
| 40 | +</template> |
| 41 | + |
| 42 | +<script> |
| 43 | + import {FormField, HandlesValidationErrors} from 'laravel-nova' |
| 44 | + import {PreviewHtml} from './PreviewHtml' |
| 45 | +
|
| 46 | + export default { |
| 47 | + mixins: [FormField, HandlesValidationErrors], |
| 48 | +
|
| 49 | + components: [ |
| 50 | + PreviewHtml, |
| 51 | + ], |
| 52 | +
|
| 53 | + props: ['resourceName', 'resourceId', 'field'], |
| 54 | +
|
| 55 | + methods: { |
| 56 | + /* |
| 57 | + * Set the initial, internal value for the field. |
| 58 | + */ |
| 59 | + setInitialValue() { |
| 60 | + this.value = this.field.value || '' |
| 61 | + }, |
| 62 | +
|
| 63 | + /** |
| 64 | + * Fill the given FormData object with the field's internal value. |
| 65 | + */ |
| 66 | + fill(formData) { |
| 67 | + formData.append(this.field.attribute, this.value) |
| 68 | + }, |
| 69 | +
|
| 70 | + /** |
| 71 | + * Update the field's internal value. |
| 72 | + */ |
| 73 | + handleChange(value) { |
| 74 | + this.value = value |
| 75 | + }, |
| 76 | + }, |
| 77 | +
|
| 78 | + computed: { |
| 79 | + defaultAttributes() { |
| 80 | + return { |
| 81 | + rows: 10, |
| 82 | + class: this.errorClasses, |
| 83 | + placeholder: this.field.name, |
| 84 | + } |
| 85 | + }, |
| 86 | +
|
| 87 | + extraAttributes() { |
| 88 | + const attrs = this.field.extraAttributes || []; |
| 89 | +
|
| 90 | + return { |
| 91 | + ...this.defaultAttributes, |
| 92 | + ...attrs, |
| 93 | + } |
| 94 | + }, |
| 95 | +
|
| 96 | + }, |
| 97 | + } |
| 98 | +</script> |
0 commit comments