From 27d3a44f4d409a2be896a72d30703a43ba8d071d Mon Sep 17 00:00:00 2001 From: shyam pandey Date: Wed, 25 Feb 2026 17:16:01 +0530 Subject: [PATCH 1/4] Add inline validation for preset fields with regex pattern --- modules/ui/fields/input.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index f505feeeb1..4fc3b42988 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -108,6 +108,15 @@ export function uiFieldText(field, context) { wrap.call(_lengthIndicator); + if (wrap.select('.field-validation-message').empty()) { + wrap.append('div') + .attr('class', 'field-validation-message') + .style('display', 'none') + .style('font-size', '12px') + .style('margin-top', '4px') + .style('color', '#888'); + } + if (field.type === 'tel') { updatePhonePlaceholder(); @@ -435,6 +444,28 @@ export function uiFieldText(field, context) { return function() { var t = {}; var val = utilGetSetValue(input); + const validationMessage = wrap.select('.field-validation-message'); + + if (field.pattern && val) { + let regex = null; + + try { + regex = new RegExp(field.pattern); + } catch (e) { + regex = null; + } + + if (regex && !regex.test(val)) { + validationMessage + .style('display', 'block') + .text('Value does not match expected format'); + } else { + validationMessage.style('display', 'none'); + } + + } else { + validationMessage.style('display', 'none'); + } if (!onInput) val = context.cleanTagValue(val); // don't override multiple values with blank string From 10252e949ed1fe838735e3c26d086eb89a5e2f22 Mon Sep 17 00:00:00 2001 From: shyam pandey Date: Thu, 26 Feb 2026 16:56:31 +0530 Subject: [PATCH 2/4] After implementing all important suggested changes --- modules/ui/fields/input.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 4fc3b42988..13f19fc3d4 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -110,11 +110,7 @@ export function uiFieldText(field, context) { if (wrap.select('.field-validation-message').empty()) { wrap.append('div') - .attr('class', 'field-validation-message') - .style('display', 'none') - .style('font-size', '12px') - .style('margin-top', '4px') - .style('color', '#888'); + .attr('class', 'field-validation-message hide'); } if (field.type === 'tel') { @@ -441,6 +437,7 @@ export function uiFieldText(field, context) { function change(onInput) { + return function() { var t = {}; var val = utilGetSetValue(input); @@ -458,7 +455,7 @@ export function uiFieldText(field, context) { if (regex && !regex.test(val)) { validationMessage .style('display', 'block') - .text('Value does not match expected format'); + .text(localizer.t('validation.value_does_not_match_expected_format')); } else { validationMessage.style('display', 'none'); } From d71b5e22ed4adcba5fc7594a01c499dc9b9b9891 Mon Sep 17 00:00:00 2001 From: shyam pandey Date: Fri, 27 Feb 2026 10:41:04 +0530 Subject: [PATCH 3/4] Same as before but optimal way to solve same problem --- modules/ui/fields/input.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 13f19fc3d4..84602e7e4f 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -442,8 +442,10 @@ export function uiFieldText(field, context) { var t = {}; var val = utilGetSetValue(input); const validationMessage = wrap.select('.field-validation-message'); - - if (field.pattern && val) { + if (!field.pattern && field.key === 'website') { + field.pattern = '^https?://.+'; + } + if (!onInput && field.pattern && val) { let regex = null; try { @@ -454,14 +456,14 @@ export function uiFieldText(field, context) { if (regex && !regex.test(val)) { validationMessage - .style('display', 'block') - .text(localizer.t('validation.value_does_not_match_expected_format')); + .classed('hide', false) + .text(localizer.t('inspector.invalid_format')); } else { - validationMessage.style('display', 'none'); + validationMessage.classed('hide', true); } - } else { - validationMessage.style('display', 'none'); + } else if(!onInput) { + validationMessage.classed('hide', true); } if (!onInput) val = context.cleanTagValue(val); From 34c6e070ff9664e48744cedab29476f2c4241e7d Mon Sep 17 00:00:00 2001 From: shyam pandey Date: Mon, 2 Mar 2026 12:46:30 +0530 Subject: [PATCH 4/4] After removing temporary added pattern for testing --- modules/ui/fields/input.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 84602e7e4f..768a527fa5 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -442,9 +442,6 @@ export function uiFieldText(field, context) { var t = {}; var val = utilGetSetValue(input); const validationMessage = wrap.select('.field-validation-message'); - if (!field.pattern && field.key === 'website') { - field.pattern = '^https?://.+'; - } if (!onInput && field.pattern && val) { let regex = null;