Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read only form fields #12244

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/bbui/src/Form/Core/Checkbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let id = null
export let text = null
export let disabled = false
export let readonly = false
export let size
export let indeterminate = false

Expand All @@ -29,6 +30,11 @@
checked={value}
{disabled}
on:change={onChange}
on:click={e => {
if (readonly) {
e.preventDefault()
}
}}
melohagan marked this conversation as resolved.
Show resolved Hide resolved
type="checkbox"
class="spectrum-Checkbox-input"
{id}
Expand Down
6 changes: 6 additions & 0 deletions packages/bbui/src/Form/Core/CheckboxGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let options = []
export let error = null
export let disabled = false
export let readonly = false
export let getOptionLabel = option => option
export let getOptionValue = option => option

Expand Down Expand Up @@ -40,6 +41,11 @@
>
<input
on:change={onChange}
on:click={e => {
if (readonly) {
e.preventDefault()
}
}}
melohagan marked this conversation as resolved.
Show resolved Hide resolved
type="checkbox"
class="spectrum-Checkbox-input"
value={optionValue}
Expand Down
4 changes: 3 additions & 1 deletion packages/bbui/src/Form/Core/DatePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export let id = null
export let disabled = false
export let readonly = false
export let error = null
export let enableTime = true
export let value = null
Expand Down Expand Up @@ -186,7 +187,7 @@
>
<div
id={flatpickrId}
class:is-disabled={disabled}
class:is-disabled={disabled || readonly}
class:is-invalid={!!error}
class="flatpickr spectrum-InputGroup spectrum-Datepicker"
class:is-focused={open}
Expand All @@ -211,6 +212,7 @@
{/if}
<input
{disabled}
{readonly}
data-input
type="text"
class="spectrum-Textfield-input spectrum-InputGroup-input"
Expand Down
6 changes: 6 additions & 0 deletions packages/bbui/src/Form/Core/RadioGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let options = []
export let error = null
export let disabled = false
export let readonly = false
export let getOptionLabel = option => option
export let getOptionValue = option => option
export let getOptionTitle = option => option
Expand Down Expand Up @@ -43,6 +44,11 @@
>
<input
on:change={onChange}
on:click={e => {
if (readonly) {
e.preventDefault()
}
}}
melohagan marked this conversation as resolved.
Show resolved Hide resolved
bind:group={value}
value={getOptionValue(option)}
type="radio"
Expand Down
2 changes: 2 additions & 0 deletions packages/bbui/src/Form/Core/RichTextField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let value = ""
export let placeholder = null
export let disabled = false
export let readonly = false
export let error = null
export let height = null
export let id = null
Expand All @@ -20,6 +21,7 @@
{fullScreenOffset}
{disabled}
{easyMDEOptions}
{readonly}
on:change
/>
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/bbui/src/Form/Core/TextArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export let value = ""
export let placeholder = null
export let disabled = false
export let readonly = false
export let error = null
export let id = null
export let height = null
Expand Down Expand Up @@ -61,6 +62,7 @@
class="spectrum-Textfield-input"
style={align ? `text-align: ${align}` : ""}
{disabled}
{readonly}
{id}
on:focus={() => (focus = true)}
on:blur={onChange}
Expand Down
2 changes: 2 additions & 0 deletions packages/bbui/src/Form/DatePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export let label = null
export let labelPosition = "above"
export let disabled = false
export let readonly = false
export let error = null
export let enableTime = true
export let timeOnly = false
Expand All @@ -33,6 +34,7 @@
<DatePicker
{error}
{disabled}
{readonly}
{value}
{placeholder}
{enableTime}
Expand Down
5 changes: 4 additions & 1 deletion packages/bbui/src/Markdown/MarkdownEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let id = null
export let fullScreenOffset = 0
export let disabled = false
export let readonly = false
export let easyMDEOptions

const dispatch = createEventDispatcher()
Expand All @@ -19,6 +20,7 @@
// control
$: checkValue(value)
$: mde?.codemirror.on("change", debouncedUpdate)
$: mde?.codemirror.setOption("readOnly", readonly)

const checkValue = val => {
if (mde && val !== latestValue) {
Expand All @@ -43,7 +45,7 @@
const debouncedUpdate = debounce(update, 250)
</script>

{#key height}
{#key (height, readonly)}
melohagan marked this conversation as resolved.
Show resolved Hide resolved
<SpectrumMDE
bind:mde
scroll={true}
Expand All @@ -54,6 +56,7 @@
easyMDEOptions={{
initialValue: value,
placeholder,
toolbar: disabled || readonly ? false : undefined,
...easyMDEOptions,
}}
/>
Expand Down
119 changes: 112 additions & 7 deletions packages/client/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "text",
"label": "Initial form step",
Expand Down Expand Up @@ -2738,6 +2749,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "validation/string",
"label": "Validation",
Expand Down Expand Up @@ -2829,6 +2851,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "validation/number",
"label": "Validation",
Expand Down Expand Up @@ -3049,6 +3082,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "select",
"label": "Options source",
Expand Down Expand Up @@ -3174,6 +3218,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "select",
"label": "Type",
Expand Down Expand Up @@ -3348,6 +3403,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "validation/boolean",
"label": "Validation",
Expand Down Expand Up @@ -3427,6 +3493,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "validation/string",
"label": "Validation",
Expand Down Expand Up @@ -3508,6 +3585,17 @@
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
},
{
"type": "validation/datetime",
"label": "Validation",
Expand Down Expand Up @@ -3781,7 +3869,7 @@
},
{
"type": "boolean",
"label": "Disabled",
"label": "Read only",
"key": "disabled",
"defaultValue": false
},
Expand Down Expand Up @@ -3857,6 +3945,17 @@
"label": "Disabled",
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
}
]
},
Expand Down Expand Up @@ -3909,6 +4008,17 @@
"label": "Disabled",
"key": "disabled",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "readonly",
"defaultValue": false,
"dependsOn": {
"setting": "disabled",
"value": true,
"invert": true
}
}
]
},
Expand Down Expand Up @@ -5530,12 +5640,7 @@
"type": "boolean",
"label": "Disabled",
"key": "disabled",
"defaultValue": false,
"dependsOn": {
"setting": "actionType",
"value": "View",
"invert": true
}
"defaultValue": false
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
actionType: actionType === "Create" ? "Create" : "Update",
dataSource,
size,
disabled: disabled || actionType === "View",
disabled,
readonly: !disabled && actionType === "View",
}}
styles={{
normal: {
Expand Down
Loading
Loading