Skip to content

Instantly share code, notes, and snippets.

@devoltt
Created May 22, 2020 11:14
Show Gist options
  • Save devoltt/2c42c3687ca2330fef2669978a0b6c26 to your computer and use it in GitHub Desktop.
Save devoltt/2c42c3687ca2330fef2669978a0b6c26 to your computer and use it in GitHub Desktop.
<template>
...
</template>
<script>
import { FormField, HandlesValidationErrors } from 'laravel-nova'
export default {
mixins: [FormField, HandlesValidationErrors],
components: { },
props: ['resourceName', 'resourceId', 'field'],
data: () => ({
selectedWebinarId: null,
}),
methods: {
...
findWatchableComponentAttribute(component) {
let attribute;
switch(component.field.component) {
case 'belongs-to-many-field':
case 'belongs-to-field':
attribute = 'selectedResource';
break;
case 'morph-to-field':
attribute = 'fieldTypeName';
break;
default:
attribute = 'value';
}
return attribute;
},
getComponentByField(component, fieldName) {
if (component.field && component.field.attribute === fieldName) {
return component;
}
let result, child;
if (component.$children.length) {
for (child of component.$children) {
result = this.getComponentByField(child, fieldName);
if (result) {
return result
}
}
}
},
loadWebinarPrices(webinarId) {
this.selectedWebinarId = webinarId
// TODO: ajax load nomenclature
}
},
mounted() {
let webinarField = this.getComponentByField(this.$root, 'webinar')
let attribute = this.findWatchableComponentAttribute(webinarField)
webinarField.$watch(attribute, option => {
this.loadWebinarPrices(option.value)
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment