Skip to content
Snippets Groups Projects
Commit ae528cc8 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge branch 'user-config-booleans' into 'master'

Support booleans in user configuration

Closes #950

See merge request !1235
parents ab79ff05 36668368
No related branches found
No related tags found
1 merge request!1235Support booleans in user configuration
<template>
<div>
<input
:id="fieldLabel"
type="checkbox"
class="switch is-rtl is-rounded is-info"
:checked="value"
v-on:change="$emit('input', $event.target.checked)"
/>
<label class="label" :for="fieldLabel"></label>
</div>
</template>
<script>
export default {
props: {
field: {
type: Object,
required: true
},
value: {
type: Boolean,
required: true
},
fieldId: {
type: String,
required: true
}
},
computed: {
fieldLabel () {
return 'boolean-toggle-' + this.fieldId
}
}
}
</script>
......@@ -2,6 +2,7 @@ import IntegerField from './IntegerField'
import FloatField from './FloatField'
import ChoicesField from './ChoicesField'
import StringField from './StringField'
import BooleanField from './BooleanField'
import { toNumber } from 'lodash'
export default {
......@@ -33,5 +34,12 @@ export default {
if (!(field.choices.includes(value))) throw new Error(`${value} is not a valid option.`)
return value
}
},
bool: {
component: BooleanField,
validate (value, field) {
if (typeof value !== 'boolean') throw new Error('Value must be a valid boolean.')
return value
}
}
}
......@@ -47,6 +47,7 @@
v-if="FIELDS[field.type]"
:is="FIELDS[field.type].component"
:field="field"
:field-id="key"
:class="{ 'is-danger': Boolean(configurationErrors[key]) }"
v-model="rawFormConfiguration[key]"
/>
......@@ -115,7 +116,7 @@ export default {
return filledForm
},
formConfiguration () {
if (this.stringConfiguration && !this.JSONConfigError) return JSON.parse(this.stringConfiguration)
if (this.JSONStringToggled && this.stringConfiguration && !this.JSONConfigError) return JSON.parse(this.stringConfiguration)
else if (this.rawFormConfiguration && !this.hasConfigurationError) return this.rawFormConfiguration
else return this.defaultConfiguration
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment