We have set up a Umbraco form and would like to use Umbraco to compare the two email addresses (Customer email and Customer confirm email field) and signal if the second one is different from the first one.
I am using Umbraco 9, not sure how to add js to a form defined in backoffice. for now I added my script to another js that is loaded by a custom field type. In this script I added code to the onclick event of the "submitbtn" button, isn't there a standard way to do this? This doesn´t look like the better way to accomplish this. Thanks.
In terms of front end it is your Javascript. If you have a site built in react or view for example then coding will be one way. Pure Javascript will be another, if your using jQuery then it will be something else so the exact Javascript you use depends on the site setup you have. With that hopefully that JavaScript is not just all inline everywhere and in a JS or series of JS files, there is nothing in the back office you do. You would target from elements based on user actions so on blur events of an input field, onChange of a dropdown and so on.
I didn´t get your answer about front end, do you know Umbraco forms in version 9? They are build in the backoffice, so there is no javascript or react or view there, Umbraco generates everything and put the code in a database. In any case I am new in Umbraco (I have just 2 weeks using it) and since right now my js is working, we are fine, but I wanted something more easy and "normal" to capture, lets say, the submit event in client-side. I suppose making simple validations in client side is very normal and I want to suppose Umbraco allows us to add that validation in an easy and direct way, not using a workaround as I added. Thanks.
Of course I know Umbraco 9 (and 10) - .Net Core basically (Yes .Net but new .Net is all about the core) (Not it is not all in the database either)
You are telling me you do not know how to code front end Javascript? It has nothing to do with how you code in .NET nor how Umbraco works.
IT IS NOTHING to do with a workaround.
Please, trying to help you so need to understand your thinking is not right so please do not lead as if that is correct.
When you have output rendered from your views in HTML that has nothing to do with Umbraco then. What your Javascript you code that is called in your site works through the DOM on that rendered page.
Basics of Javascript. Targeting a form, HTML, Manipulating the DOM is all outside of Umbraco, the backoffice and Umbraco forms.
What do you have?
You have a CSS yes?
You have Javascript doing anything on your site?
Can you show what sort of javascript you are currently using in your form field? We might be able to just load that on the normal page if it doesn't do anything strange. So you wouldn't have to have a custom field in Umbraco for it.
Hi Patrick,
first of all: the custom field I am using is necessary because we are dynamically adding dropdowns (selects) and inputs with an "add line" button, so even without any validation, we need the custom field.
The javascript I am using is to validate if all the dropdowns have a selected value, and if inputs for quantities haven been filled. Also, it is validating if duplicated values (same value in 2 or more selects) have been selected.
Javascript:
Since this is used in several forms, we do this to add the listener to onclick to submit button:
if (document.getElementsByName("submitbtn")[0].value == "Register Opportunity")
document.getElementsByName("submitbtn")[0].onclick = validateOpportunityRegistration;
The validateOpportunityRegistration function gets the selects, nothing complex, to check if all of them have a selected value, and also checks the inputs to see if they have numeric values.
Umbraco Forms add custom validation
Hi
We have set up a Umbraco form and would like to use Umbraco to compare the two email addresses (Customer email and Customer confirm email field) and signal if the second one is different from the first one.
What’s the best approach for it?
Thanks
Without going hard into custom validation and backend code most sites just do Javascript based solutions so you can be more dynamic.
It all depends on your code setup and what Javascript framework you use but on the most basic level your code is..
What would this look like in Regex if I were to set this up on the front end of umbraco forms using custom validation?
Regex is for matching a pattern / pattern ruleset though, not really for for matching/comparing two strings.
Hi, where can I add this kind of validations? Thanks.
In what ever Javascript setup you have.
I am using Umbraco 9, not sure how to add js to a form defined in backoffice. for now I added my script to another js that is loaded by a custom field type. In this script I added code to the onclick event of the "submitbtn" button, isn't there a standard way to do this? This doesn´t look like the better way to accomplish this. Thanks.
You can do front end validation and back end validation.
I didn´t get your answer about front end, do you know Umbraco forms in version 9? They are build in the backoffice, so there is no javascript or react or view there, Umbraco generates everything and put the code in a database. In any case I am new in Umbraco (I have just 2 weeks using it) and since right now my js is working, we are fine, but I wanted something more easy and "normal" to capture, lets say, the submit event in client-side. I suppose making simple validations in client side is very normal and I want to suppose Umbraco allows us to add that validation in an easy and direct way, not using a workaround as I added. Thanks.
Of course I know Umbraco 9 (and 10) - .Net Core basically (Yes .Net but new .Net is all about the core) (Not it is not all in the database either)
You are telling me you do not know how to code front end Javascript? It has nothing to do with how you code in .NET nor how Umbraco works.
IT IS NOTHING to do with a workaround. Please, trying to help you so need to understand your thinking is not right so please do not lead as if that is correct.
When you have output rendered from your views in HTML that has nothing to do with Umbraco then. What your Javascript you code that is called in your site works through the DOM on that rendered page. Basics of Javascript. Targeting a form, HTML, Manipulating the DOM is all outside of Umbraco, the backoffice and Umbraco forms.
What do you have? You have a CSS yes? You have Javascript doing anything on your site?
This is a 30 second Codepen search and a pure Javascript validation of a from https://codepen.io/benabbottnz/pen/kGxQGG
Hi Fernando,
Can you show what sort of javascript you are currently using in your form field? We might be able to just load that on the normal page if it doesn't do anything strange. So you wouldn't have to have a custom field in Umbraco for it.
Hi Patrick, first of all: the custom field I am using is necessary because we are dynamically adding dropdowns (selects) and inputs with an "add line" button, so even without any validation, we need the custom field.
The javascript I am using is to validate if all the dropdowns have a selected value, and if inputs for quantities haven been filled. Also, it is validating if duplicated values (same value in 2 or more selects) have been selected.
Javascript: Since this is used in several forms, we do this to add the listener to onclick to submit button:
The validateOpportunityRegistration function gets the selects, nothing complex, to check if all of them have a selected value, and also checks the inputs to see if they have numeric values.
Thanks.
is working on a reply...