Skip to content

Commit

Permalink
Add readOnlyValue prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjahr committed Jan 1, 2022
1 parent 72fe0ba commit ee83e3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/checkbox-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
type='checkbox'
:name='name'
:id='name'
v-model='value'
:checked='computedValue'
@change='onChange'
@click='onClick'
)
//- Visual checkbox
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/concerns/is-field.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default

data: ->
# Set initial value to @default prop if provided.
value: @default || ''
value: ''

# Tooltip state
tooltipActive: false
Expand Down

0 comments on commit ee83e3e

Please sign in to comment.