0

I have requirement to match 2 field values in Sitecore Form. If value doesn't match then form shouldn't get submitted. How to handle this scenario.

2
  • Sitecore forms provide email/password confirmation fields out of the box. Have you used custom form fields for your requirements? Dec 5, 2022 at 5:34
  • I need to apply that on 2 Single Line(OOTB) Text field.
    – Vikram
    Dec 5, 2022 at 7:21

2 Answers 2

1

I would say use OOTB conditional logic for your forms. Check if this is possible by following the link - https://doc.sitecore.com/xp/en/developers/93/sitecore-experience-manager/use-conditional-logic-for-your-forms.html

To add conditions:

  1. On the form canvas, click a form element to select it.

  2. In the relevant field, in the Form elements pane, in the Conditions section, click Edit Conditions.

  3. In the Conditions dialog box, add the relevant conditions. For example, if for a survey commentary you want to know the reasons for people rating your product poorly, you can display a multiline field. If visitors rate the product well, you can display the submit button. To do this, click Add condition and enter the IF and THEN fields.

Note: Depending on the element you select, the available options from the drop-down list in the target field can differ.

You can add multiple actions for different target fields in a single condition group. If the conditions evaluate to true, all actions will be executed.

enter image description here

  1. Click Apply and save the form.

  2. The conditions now display in the Form elements pane. Click Edit conditions to change them.

enter image description here

Option 2 : If above option is not working then try to Create New Conditions by following -https://inspeerity.com/blog/sitecore-forms-create-new-conditions

Below is for showing Single line field based on radio button, so you can use something like this.

  1. Sitecore – create new action type (clear) under /sitecore/system/Settings/Forms/Meta Data/Conditions/Action Types/

enter image description here

  1. JS – add new action, just after disable action:

clear: function($target, action, conditionsResult) { if(conditionsResult) { $target.val(""); } },

  1. JS – add new line with clear in actionLinks, so it would look like this:

actionLinks: { show: "hide", enable: "disable", clear: "clear", "go to page": "go to page" },

And now you’ll just have to set this new condition in form editor and see the result.

0

It could be possible with Sitecore Forms Conditional Validation, Here is the link that matches your case https://www.oshyn.com/blog/sitecore-forms-conditional-validation-p1

Just a few twics are required

  1. You need to use Single line text rather than Number.
  2. Update form.custom.validation.js file (just remove number checking) && !isNaN(otherField.val()) && !isNaN(value)
  3. Compare with "=" instead of ">" or you can update the code to compare string with string.Equals(val, "astringvalue", StringComparison.OrdinalIgnoreCase) in Validator class

I'd also recommend updating variables and method names as per your requirement and cleaning up the redundant code. I'd strongly recommend server-side validation as well for such implementation.

I tried by my self and here is the result. enter image description here

I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.