add nova
This commit is contained in:
75
nova/resources/js/mixins/FormEvents.js
Normal file
75
nova/resources/js/mixins/FormEvents.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import isNil from 'lodash/isNil'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
formUniqueId: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
emitFieldValue(attribute, value) {
|
||||
Nova.$emit(`${attribute}-value`, value)
|
||||
|
||||
if (this.hasFormUniqueId === true) {
|
||||
Nova.$emit(`${this.formUniqueId}-${attribute}-value`, value)
|
||||
}
|
||||
},
|
||||
|
||||
emitFieldValueChange(attribute, value) {
|
||||
Nova.$emit(`${attribute}-change`, value)
|
||||
|
||||
if (this.hasFormUniqueId === true) {
|
||||
Nova.$emit(`${this.formUniqueId}-${attribute}-change`, value)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get field attribute value event name.
|
||||
*/
|
||||
getFieldAttributeValueEventName(attribute) {
|
||||
return this.hasFormUniqueId === true
|
||||
? `${this.formUniqueId}-${attribute}-value`
|
||||
: `${attribute}-value`
|
||||
},
|
||||
|
||||
/**
|
||||
* Get field attribue value event name.
|
||||
*/
|
||||
getFieldAttributeChangeEventName(attribute) {
|
||||
return this.hasFormUniqueId === true
|
||||
? `${this.formUniqueId}-${attribute}-change`
|
||||
: `${attribute}-change`
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
/**
|
||||
* Return the field attribute.
|
||||
*/
|
||||
fieldAttribute() {
|
||||
return this.field.attribute
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine if the field has Form Unique ID.
|
||||
*/
|
||||
hasFormUniqueId() {
|
||||
return !isNil(this.formUniqueId) && this.formUniqueId !== ''
|
||||
},
|
||||
|
||||
/**
|
||||
* Get field attribue value event name.
|
||||
*/
|
||||
fieldAttributeValueEventName() {
|
||||
return this.getFieldAttributeValueEventName(this.fieldAttribute)
|
||||
},
|
||||
|
||||
/**
|
||||
* Get field attribue value event name.
|
||||
*/
|
||||
fieldAttributeChangeEventName() {
|
||||
return this.getFieldAttributeChangeEventName(this.fieldAttribute)
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user