[AEM6.5] Dialog Validation : Compare two textfield and value should be same. | Community
Skip to main content
tushaar_srivastava
Level 6
January 25, 2023
Solved

[AEM6.5] Dialog Validation : Compare two textfield and value should be same.

  • January 25, 2023
  • 1 reply
  • 1112 views

Hi All,
I need to restrict author to put different name in given text field the value that they are authoring, it should be same. example:
We have 2 tabs : Name and Category. having textfield in it.

Now Author Should enter same values, means the value of Category should be same as Name or vice-versa. otherwise dialog will not save and shows error: value should be same.

I am trying to use Validator framework. and since it is component level validation I have created clientlibs under component, and provided clientlib category to component dialog using extraClientlibs : [categoryname].

 


Can anyone suggest me how to handle the validation of two fields.
validation =name-validation for Name tab and 
validation =category-validation for Category tab

(function($, Coral) { "use strict"; var registry = $(window).adaptTo("foundation-registry"); registry.register("foundation.validation.validator", { selector: "[data-validation=name-validation]", validate: function(element) { // } }); })(jQuery, Coral);


or is there any other better way to do this task


Thanks.
@arunpatidar  @kautuk_sahni  @briankasingli  @krati_garg  @aanchal-sikka 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

@tushaar_srivastava  Try below code snippet and change names accordingly, I have used category and title as files names. Shouls be same as name property value in dialog field.

(function($, Coral) { "use strict"; var registry = $(window).adaptTo("foundation-registry"); registry.register("foundation.validation.validator", { selector: "[name='./category']", validate: function(element) { let title = $("[name='./title']").val(); if(title !== element.value) { return "Value is not same as Title"; } return; } }); })(jQuery, Coral);

  

1 reply

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
January 25, 2023

@tushaar_srivastava  Try below code snippet and change names accordingly, I have used category and title as files names. Shouls be same as name property value in dialog field.

(function($, Coral) { "use strict"; var registry = $(window).adaptTo("foundation-registry"); registry.register("foundation.validation.validator", { selector: "[name='./category']", validate: function(element) { let title = $("[name='./title']").val(); if(title !== element.value) { return "Value is not same as Title"; } return; } }); })(jQuery, Coral);

  

tushaar_srivastava
Level 6
January 25, 2023

Thank you @anudeep_garnepudi , this worked and I was making code more complex by registring two different validators. and trying to pass as Array.
This really helped. 😊