Merge pull request #4323 from Budibase/relationship-field-default-value

Relationship field default value
This commit is contained in:
Andrew Kingston 2022-02-04 11:03:48 +00:00 committed by GitHub
commit de3bf659f5
3 changed files with 46 additions and 4 deletions

View File

@ -8,9 +8,34 @@
copyToClipboard(value) copyToClipboard(value)
} }
function copyToClipboard(value) { const copyToClipboard = value => {
navigator.clipboard.writeText(value).then(() => { return new Promise(res => {
notifications.success("Copied") if (navigator.clipboard && window.isSecureContext) {
// Try using the clipboard API first
navigator.clipboard.writeText(value).then(res)
} else {
// Fall back to the textarea hack
let textArea = document.createElement("textarea")
textArea.value = value
textArea.style.position = "fixed"
textArea.style.left = "-9999px"
textArea.style.top = "-9999px"
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
document.execCommand("copy")
textArea.remove()
res()
}
})
.then(() => {
notifications.success("Copied to clipboard")
})
.catch(() => {
notifications.error(
"Failed to copy to clipboard. Check the dev console for the value."
)
console.warn("Failed to copy the value", value)
}) })
} }
</script> </script>

View File

@ -2537,6 +2537,11 @@
"label": "Placeholder", "label": "Placeholder",
"key": "placeholder" "key": "placeholder"
}, },
{
"type": "text",
"label": "Default value",
"key": "defaultValue"
},
{ {
"type": "boolean", "type": "boolean",
"label": "Autocomplete", "label": "Autocomplete",

View File

@ -12,6 +12,7 @@
export let disabled = false export let disabled = false
export let validation export let validation
export let autocomplete = false export let autocomplete = false
export let defaultValue
let fieldState let fieldState
let fieldApi let fieldApi
@ -27,6 +28,7 @@
$: singleValue = flatten(fieldState?.value)?.[0] $: singleValue = flatten(fieldState?.value)?.[0]
$: multiValue = flatten(fieldState?.value) ?? [] $: multiValue = flatten(fieldState?.value) ?? []
$: component = multiselect ? CoreMultiselect : CoreSelect $: component = multiselect ? CoreMultiselect : CoreSelect
$: expandedDefaultValue = expand(defaultValue)
const fetchTable = async id => { const fetchTable = async id => {
if (id) { if (id) {
@ -62,6 +64,16 @@
const multiHandler = e => { const multiHandler = e => {
fieldApi.setValue(e.detail) fieldApi.setValue(e.detail)
} }
const expand = values => {
if (!values) {
return []
}
if (Array.isArray(values)) {
return values
}
return values.split(",").map(value => value.trim())
}
</script> </script>
<Field <Field
@ -69,11 +81,11 @@
{field} {field}
{disabled} {disabled}
{validation} {validation}
defaultValue={expandedDefaultValue}
type={FieldTypes.LINK} type={FieldTypes.LINK}
bind:fieldState bind:fieldState
bind:fieldApi bind:fieldApi
bind:fieldSchema bind:fieldSchema
defaultValue={[]}
> >
{#if fieldState} {#if fieldState}
<svelte:component <svelte:component