Skip to content

Beautiful Open-Source Form Builder

Fix phone regex condition inputs (#1319)

Julien Nahum433acd4b59cd
diff --git a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue b/client/components/open/forms/components/form-logic-components/ColumnCondition.vue
index 977ab6b6a..c81ff6b90 100644
--- a/client/components/open/forms/components/form-logic-components/ColumnCondition.vue
+++ b/client/components/open/forms/components/form-logic-components/ColumnCondition.vue
@@ -121,6 +121,12 @@ export default {
componentData.columns = this.property.columns
}
+ // Regex patterns are plain text, regardless of the field being checked.
+ // In particular, PhoneInput would format/reject the regex as a phone number.
+ if (this.selectedOperator()?.format?.type === 'regex') {
+ componentData.component = "TextInput"
+ }
+
// Pass mention props for MentionInput
if (componentData.component === 'MentionInput') {
componentData.mentions = this.mentionFields
diff --git a/client/test/nuxt/column-condition.component.spec.ts b/client/test/nuxt/column-condition.component.spec.ts
index c15df2944..1f4cec9a3 100644
--- a/client/test/nuxt/column-condition.component.spec.ts
+++ b/client/test/nuxt/column-condition.component.spec.ts
@@ -68,6 +68,8 @@ function mountColumnCondition({
props: ['modelValue', 'items'],
},
MentionInput: mentionInputStub,
+ TextInput: { name: 'TextInput', inheritAttrs: false, props: ['modelValue'], emits: ['update:modelValue'], template: '<input />' },
+ PhoneInput: true,
},
},
})
@@ -99,3 +101,33 @@ describe('ColumnCondition computed mentions', () => {
expect(wrapper.vm.castContent({ value: mentionValue }).value).toBe(mentionValue)
})
})
+
+
+describe('ColumnCondition phone regex patterns', () => {
+ it.each(['matches_regex', 'does_not_match_regex'])('accepts a plain text pattern for %s', async (operator) => {
+ const wrapper = mountColumnCondition({
+ property: { id: 'phone', name: 'Phone', type: 'phone_number' } as any,
+ modelValue: { operator, value: '^\\+?[0-9]{10,15}$' },
+ })
+ await flushPromises()
+
+ expect(wrapper.vm.inputComponentData.component).toBe('TextInput')
+ const input = wrapper.findComponent({ name: 'TextInput' })
+ expect(input.exists()).toBe(true)
+ input.vm.$emit('update:modelValue', '^0[1-9][0-9]{8}$')
+ await flushPromises()
+ expect(wrapper.emitted('update:modelValue')?.at(-1)?.[0]).toMatchObject({
+ operator, value: '^0[1-9][0-9]{8}$',
+ })
+ wrapper.unmount()
+ })
+
+ it('keeps the phone input for a phone equality condition', () => {
+ const wrapper = mountColumnCondition({
+ property: { id: 'phone', name: 'Phone', type: 'phone_number' } as any,
+ modelValue: { operator: 'equals', value: '+33123456789' },
+ })
+ expect(wrapper.vm.inputComponentData.component).toBe('PhoneInput')
+ wrapper.unmount()
+ })
+})