You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text type fields have a dropdown for common regexs to use for validation. Currently there is no way for developers to add additional regular expressions to this list, which only contains a few basic options, without modifying core forms JS files. This is even trickier now that most of the files are compiled into the assembly. You can paste the regex in manually, but that's not really feasible/practical for your average CMS user.
We've had a bunch of requirements over the years to create fields that validate to various approved regexs (for example NI numbers, or customer account numbers), that you might need to use in more that one form. You end up having to create a custom field type for each time you want a re-usable regex, which is fine, but you can soon end up with a large number of custom fields if you need a lot of them. It would be really handy if there was a way to hook into the list of regexs for validation as a developer and add in additional items.
The text was updated successfully, but these errors were encountered:
We've prepared this now for the next minor release of Forms 10+. It'll work like the other "providers" that you can register and update what we ship by default in the product. So for example, with the following code, you can remove one of the core ones and add one of your own.
public class TestSiteComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.FormsValidationPatterns()
.InsertAfter<Email, NumberOneToFive>()
.Remove<Number>();
}
}
And to implement one, you would use the IValidationPattern interface, like this:
public class NumberOneToFive : IValidationPattern
{
public string Alias => "numberOnToFive";
public string Name => "Number (1-5)";
public string LabelKey => string.Empty;
public string Pattern => @"^[1-5]*$";
public bool ReadOnly => true;
}
You can either provide Name or a LabelKey (and if the latter is provided, it'll look for this translation key to present the correct language for the label in the backoffice).
There'll be a docs update detailing this too once the release is ready.
The text type fields have a dropdown for common regexs to use for validation. Currently there is no way for developers to add additional regular expressions to this list, which only contains a few basic options, without modifying core forms JS files. This is even trickier now that most of the files are compiled into the assembly. You can paste the regex in manually, but that's not really feasible/practical for your average CMS user.
We've had a bunch of requirements over the years to create fields that validate to various approved regexs (for example NI numbers, or customer account numbers), that you might need to use in more that one form. You end up having to create a custom field type for each time you want a re-usable regex, which is fine, but you can soon end up with a large number of custom fields if you need a lot of them. It would be really handy if there was a way to hook into the list of regexs for validation as a developer and add in additional items.
The text was updated successfully, but these errors were encountered: