From ee83e3ec6cbce7154335b80aad3baeb7fd0e88fc Mon Sep 17 00:00:00 2001 From: Jonathan Jahr Date: Fri, 31 Dec 2021 17:53:21 -0800 Subject: [PATCH] Add readOnlyValue prop --- src/components/checkbox-field.vue | 13 ++++++++++++- src/concerns/is-field.coffee | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/checkbox-field.vue b/src/components/checkbox-field.vue index 9b1b41e..31a4b5a 100644 --- a/src/components/checkbox-field.vue +++ b/src/components/checkbox-field.vue @@ -13,7 +13,8 @@ type='checkbox' :name='name' :id='name' - v-model='value' + :checked='computedValue' + @change='onChange' @click='onClick' ) //- Visual checkbox @@ -47,6 +48,9 @@ export default name: String label: String default: Boolean + # If provided, the field will show the prop value, and the value + # should be managed externally. + readOnlyValue: Boolean components: { TooltipBtn @@ -61,6 +65,13 @@ export default ...@commonClasses ] + # If readOnlyValue provided, then always show that value. + computedValue: -> if @readOnlyValue? then @readOnlyValue else @value + + methods: + # Manually do v-bind (set @value on the @changed event) + onChange: (event) -> @value = event.target.checked + watch: value: -> @state = @value state: -> @$emit 'input', @state diff --git a/src/concerns/is-field.coffee b/src/concerns/is-field.coffee index 9b1d4dc..299b414 100644 --- a/src/concerns/is-field.coffee +++ b/src/concerns/is-field.coffee @@ -24,7 +24,7 @@ export default data: -> # Set initial value to @default prop if provided. - value: @default || '' + value: '' # Tooltip state tooltipActive: false