3232 </div >
3333 </template >
3434
35+ <!-- Text-based conditions (short, long) -->
36+ <template v-else-if =" isTextBasedTrigger " >
37+ <div class =" condition-row" >
38+ <NcSelect
39+ v-model =" conditionType "
40+ :options =" textConditionTypes "
41+ :placeholder =" t (' forms' , ' Condition type' )"
42+ :ariaLabelCombobox =" t (' forms' , ' Condition type' )"
43+ label="label"
44+ :reduce =" (opt ) => opt .value "
45+ class="condition-type-select" />
46+ <NcTextField
47+ v-model =" textConditionValue "
48+ :label =" conditionValuePlaceholder "
49+ :error =" isRegexInvalid "
50+ :helperText ="
51+ isRegexInvalid
52+ ? t (
53+ ' forms' ,
54+ ' Invalid regular expression, use the format /pattern/' ,
55+ )
56+ : ' '
57+ "
58+ class="condition-value-input" />
59+ </div >
60+ </template >
61+
3562 <!-- Value-based conditions (linearscale, color) -->
3663 <template v-else-if =" isValueBasedTrigger " >
3764 <div class =" condition-row" >
@@ -147,6 +174,7 @@ import NcColorPicker from '@nextcloud/vue/components/NcColorPicker'
147174import NcDateTimePicker from ' @nextcloud/vue/components/NcDateTimePicker'
148175import NcSelect from ' @nextcloud/vue/components/NcSelect'
149176import NcTextField from ' @nextcloud/vue/components/NcTextField'
177+ import { validateExpression } from ' ../../utils/RegularExpression.ts'
150178
151179export default {
152180 name: ' BranchConditionEditor' ,
@@ -188,6 +216,13 @@ export default {
188216
189217 emits: [' update:branch' ],
190218
219+ data () {
220+ return {
221+ // Text being typed, an invalid regular expression is not saved
222+ textDraft: null ,
223+ }
224+ },
225+
191226 computed: {
192227 /**
193228 * Check if trigger is option-based (radio, dropdown, checkbox)
@@ -205,6 +240,13 @@ export default {
205240 return [' multiple_unique' , ' dropdown' ].includes (this .triggerType )
206241 },
207242
243+ /**
244+ * Check if trigger is text-based (short, long)
245+ */
246+ isTextBasedTrigger () {
247+ return [' short' , ' long' ].includes (this .triggerType )
248+ },
249+
208250 /**
209251 * Check if trigger is value-based (linearscale, color)
210252 */
@@ -262,6 +304,22 @@ export default {
262304 return this .isSingleSelect ? selected[0 ] || null : selected
263305 },
264306
307+ /**
308+ * Text condition type options
309+ */
310+ textConditionTypes () {
311+ const types = [
312+ { value: ' string_equals' , label: t (' forms' , ' Equals' ) },
313+ { value: ' string_contains' , label: t (' forms' , ' Contains' ) },
314+ { value: ' regex' , label: t (' forms' , ' Matches regex' ) },
315+ ]
316+ // Long text doesn't support string_equals
317+ if (this .triggerType === ' long' ) {
318+ return types .filter ((t ) => t .value !== ' string_equals' )
319+ }
320+ return types
321+ },
322+
265323 /**
266324 * Value condition type options (for linear scale)
267325 */
@@ -292,6 +350,7 @@ export default {
292350 * Default condition type based on trigger
293351 */
294352 defaultConditionType () {
353+ if (this .isTextBasedTrigger ) return ' string_contains'
295354 if (this .triggerType === ' linearscale' ) return ' value_equals'
296355 if (this .isDateBasedTrigger ) return ' date_range'
297356 return null
@@ -310,6 +369,29 @@ export default {
310369 },
311370 },
312371
372+ /**
373+ * Value of a text condition, regular expressions are only saved when valid
374+ */
375+ textConditionValue: {
376+ get () {
377+ return this .textDraft ?? this .conditionValue
378+ },
379+
380+ set (value ) {
381+ this .textDraft = value
382+ if (this .conditionType !== ' regex' || validateExpression (value)) {
383+ this .conditionValue = value
384+ }
385+ },
386+ },
387+
388+ isRegexInvalid () {
389+ return (
390+ this .conditionType === ' regex'
391+ && ! validateExpression (this .textConditionValue )
392+ )
393+ },
394+
313395 /**
314396 * Storage format of date and time conditions, the same as for answers
315397 */
@@ -370,6 +452,19 @@ export default {
370452 return this .branch .conditions ? .[0 ]? .fileUploaded ?? true
371453 },
372454
455+ /**
456+ * Placeholder for condition value input
457+ */
458+ conditionValuePlaceholder () {
459+ if (this .conditionType === ' regex' ) {
460+ return t (' forms' , ' Regular expression, e.g. /^yes$/i' )
461+ }
462+ if (this .conditionType === ' string_equals' ) {
463+ return t (' forms' , ' Exact text to match' )
464+ }
465+ return t (' forms' , ' Text to search for' )
466+ },
467+
373468 /**
374469 * Date picker type based on trigger type
375470 */
0 commit comments