Created
May 22, 2020 11:14
-
-
Save devoltt/2c42c3687ca2330fef2669978a0b6c26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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