Skip to content

Commit daf1e4b

Browse files
committed
feat: support readonly forms
1 parent dbf70f7 commit daf1e4b

File tree

8 files changed

+46
-12
lines changed

8 files changed

+46
-12
lines changed

packages/components-vue/src/components/Table.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
value: node[property.value],
146146
property,
147147
node,
148-
readOnly: isReadOnly,
148+
readonly: isReadOnly,
149149
theme,
150150
modalTheme,
151151
classes,
@@ -355,7 +355,7 @@
355355
* read only table
356356
* @old editable(inverse)
357357
*/
358-
readOnly?: boolean;
358+
readonly?: boolean;
359359
/**
360360
* Do nodes support pagination?
361361
*/
@@ -440,7 +440,7 @@
440440
});
441441
const isReadOnly = computed<boolean>(() => {
442442
return (
443-
props.readOnly ||
443+
props.readonly ||
444444
!props.nodes.length ||
445445
(!props.updateNode && !props.cloneNode && !props.deleteNode)
446446
);

packages/components-vue/src/components/form/Input.vue

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
:theme="theme"
1818
:aria-label="option.alias || option.value"
1919
:active="modelValue.includes(option.value)"
20-
:disabled="!input.multiple && modelValue.includes(option.value)"
20+
:disabled="readonly || (!input.multiple && modelValue.includes(option.value))"
2121
@click="choose(option.value)"
2222
>
2323
<span>{{ option.alias || option.value }}</span>
@@ -40,6 +40,7 @@
4040
<InputFile
4141
v-else-if="!input.defaults && input.type === eFT.FILE"
4242
:theme="theme"
43+
:disabled="readonly"
4344
class="--flx"
4445
:min="input.min"
4546
:max="input.max"
@@ -48,7 +49,14 @@
4849
@update:model-value="$emit('update:model-value', $event)"
4950
/>
5051
<!-- Future inner loop input -->
51-
<FormInputLoop v-else v-slot="{ i }" :models="models" :input="input" :theme="theme">
52+
<FormInputLoop
53+
v-else
54+
v-slot="{ i }"
55+
:models="models"
56+
:input="input"
57+
:theme="theme"
58+
:readonly="readonly"
59+
>
5260
<div
5361
v-if="input.defaults && input.defaults.length >= 2"
5462
class="flx --flxColumn --flxRow-wrap:md --flx-start-stretch --flx"
@@ -71,6 +79,7 @@
7179
class="--width-180 --flx"
7280
:invalid="invalid"
7381
:model-value="[model]"
82+
:disabled="readonly"
7483
@update:model-value="
7584
models[i].value = models[i].value.toSpliced(index, 1, $event[0])
7685
"
@@ -85,6 +94,7 @@
8594
v-model="models[i].value[0]"
8695
v-bind="inputProps"
8796
:theme="theme"
97+
:disabled="readonly"
8898
:placeholder="getInputPlaceholder()"
8999
type="password"
90100
class="--width-180 --flx"
@@ -93,6 +103,7 @@
93103
v-model="models[i].value[1]"
94104
v-bind="inputProps"
95105
:theme="theme"
106+
:disabled="readonly"
96107
:placeholder="getInputPlaceholder()"
97108
type="password"
98109
class="--width-180 --flx"
@@ -106,12 +117,14 @@
106117
<SelectSimple
107118
v-model="models[i].value[0]"
108119
v-bind="{ options: input.options, theme }"
120+
:disabled="readonly"
109121
class="--width-180 --flx"
110122
/>
111123
<InputText
112124
v-model="models[i].value[1]"
113125
v-bind="inputProps"
114126
:theme="theme"
127+
:disabled="readonly"
115128
:placeholder="getInputPlaceholder()"
116129
type="number"
117130
class="--width-180 --flx"
@@ -125,13 +138,15 @@
125138
<SelectSimple
126139
v-model="models[i].value[0]"
127140
:theme="theme"
141+
:disabled="readonly"
128142
:options="indicativesArr"
129143
class="--width-180 --flx"
130144
/>
131145
<InputText
132146
v-model="models[i].value[1]"
133147
v-bind="inputProps"
134148
:theme="theme"
149+
:disabled="readonly"
135150
:placeholder="getInputPlaceholder()"
136151
type="tel"
137152
class="--width-180 --flx"
@@ -152,6 +167,7 @@
152167
:value="defaultCountry"
153168
icon="earth-americas"
154169
:theme="theme"
170+
:disabled="readonly"
155171
:placeholder="getInputPlaceholder()"
156172
class="--width-180 --flx"
157173
/>
@@ -165,7 +181,7 @@
165181
name="state"
166182
icon="mountain-sun"
167183
:theme="theme"
168-
:disabled="!(models[i].value[0] || defaultCountry)"
184+
:disabled="readonly || !(models[i].value[0] || defaultCountry)"
169185
:placeholder="getInputPlaceholder(1)"
170186
class="--width-180 --flx"
171187
/>
@@ -175,7 +191,7 @@
175191
name="city"
176192
icon="city"
177193
:theme="theme"
178-
:disabled="!models[i].value[1]"
194+
:disabled="readonly || !models[i].value[1]"
179195
:placeholder="getInputPlaceholder(2)"
180196
class="--width-180 --flx"
181197
/>
@@ -198,6 +214,7 @@
198214
:placeholder="getInputPlaceholder()"
199215
type="checkbox"
200216
:theme="theme"
217+
:disabled="readonly"
201218
full-width
202219
show-placeholder
203220
>
@@ -216,6 +233,7 @@
216233
v-model="models[i].value"
217234
v-bind="inputProps"
218235
:theme="theme"
236+
:disabled="readonly"
219237
:placeholder="input.placeholder"
220238
:options="options"
221239
class="--flx"
@@ -230,6 +248,7 @@
230248
v-model="models[i].value"
231249
v-bind="inputProps"
232250
:theme="theme"
251+
:disabled="readonly"
233252
:placeholder="input.placeholder"
234253
:options="options"
235254
class="--flx"
@@ -240,6 +259,7 @@
240259
v-model="models[i].value"
241260
v-bind="inputProps"
242261
:theme="theme"
262+
:disabled="readonly"
243263
/>
244264
<!-- Future outer loop input -->
245265
<InputText
@@ -252,6 +272,7 @@
252272
: { type: getInputTextType() }),
253273
}"
254274
:theme="theme"
275+
:disabled="readonly"
255276
:placeholder="getInputPlaceholder()"
256277
class="--flx"
257278
/>
@@ -306,6 +327,8 @@
306327
invalid?: iInvalidInput;
307328
countries?: iCountry[];
308329
states?: iState[];
330+
/** Make all inputs read only by disabling them */
331+
readonly?: boolean;
309332
}
310333
311334
/**

packages/components-vue/src/components/form/InputLoop.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
v-if="input.multiple && input.min < input.values.length"
1111
:aria-label="t('clear')"
1212
:theme="theme"
13+
:disabled="readonly"
1314
@click="input.removeValue(i)"
1415
>
1516
<IconFa name="trash-can" size="20" />
@@ -26,6 +27,7 @@
2627
v-if="input.multiple && input.max > models.length"
2728
:aria-label="t('add')"
2829
:theme="theme"
30+
:disabled="readonly"
2931
@click="input.addValue()"
3032
>
3133
{{ t("add") }}
@@ -53,6 +55,8 @@
5355
export interface iFormInputLoop<Ti> extends iUseThemeProps {
5456
input: FormInputClass;
5557
models: WritableComputedRef<Ti | Ti[]>[];
58+
/** Make all inputs read only by disabling them */
59+
readonly?: boolean;
5660
}
5761
5862
/**

packages/components-vue/src/components/form/Simple.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
{{ getSuggestedTitle(input) }}
3131
</p>
3232
<FormInput
33+
:readonly="readonly"
3334
:theme="theme"
3435
:input="input"
3536
:invalid="getInvalid(input.name)"
@@ -67,6 +68,8 @@
6768
* Make model
6869
*/
6970
make?: FormInputClass[];
71+
/** Make all inputs read only by disabling them */
72+
readonly?: boolean;
7073
}
7174
7275
/**

packages/components-vue/src/components/form/Stages.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:invalid="invalid"
2222
no-form
2323
:title="form.title"
24+
:readonly="form.readonly"
2425
@update:invalid="invalid = $event"
2526
/>
2627
</div>
@@ -123,6 +124,8 @@
123124
title?: string;
124125
inputs: FormInputClass[];
125126
listen?: boolean;
127+
/** Make all inputs read only by disabling them */
128+
readonly?: boolean;
126129
}
127130
128131
interface iFormStages extends iUseThemeProps {

packages/components-vue/src/components/select/Filter.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<ActionLink
4646
v-if="model && selectOptions.length > 1"
4747
:theme="theme"
48+
:disabled="disabled"
4849
:aria-label="t('select_restablish_field')"
4950
:title="t('select_restablish_field')"
5051
@click.prevent="resetModel"

packages/components-vue/src/components/value/Complex.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:title="value.length ? t('table_quantity', value.length) : ''"
77
>
88
<ActionButton
9-
v-if="!readOnly && property?.createNode"
9+
v-if="!readonly && property?.createNode"
1010
:theme="theme"
1111
:tooltip="t('table_create_new')"
1212
tooltip-as-text
@@ -108,7 +108,7 @@
108108
value: childValueName,
109109
alias: _.capitalize(_.startCase(childValueName)),
110110
},
111-
readOnly,
111+
readonly,
112112
theme,
113113
modalTheme,
114114
modalTarget,
@@ -122,7 +122,7 @@
122122
<!-- Plain value -->
123123
<ValueSimple
124124
v-else
125-
v-bind="{ value, property, readOnly, theme, modalTheme, classes, modalTarget }"
125+
v-bind="{ value, property, readonly, theme, modalTheme, classes, modalTarget }"
126126
/>
127127
</template>
128128
<script setup lang="ts" generic="P extends Record<string, any>, T">
@@ -165,7 +165,7 @@
165165
* The value prop will be a property of this node
166166
*/
167167
node?: Pi;
168-
readOnly?: boolean;
168+
readonly?: boolean;
169169
classes?: tProps<string>;
170170
/**
171171
* Refresh the content

packages/components-vue/src/components/value/Simple.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
* Cell column property
102102
*/
103103
property?: iProperty<Pi>;
104-
readOnly?: boolean;
104+
readonly?: boolean;
105105
classes?: tProps<string>;
106106
modalTarget?: string | RendererElement;
107107
modalTheme?: tThemeTuple | tProp<tThemeModifier>;

0 commit comments

Comments
 (0)