Custom validation via other field

  • Pascal Kurmann
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 95
  • Thank you received: 0

Pascal Kurmann created the topic: Custom validation via other field

Hi,

I made this form on this page: www.balu-topf.ch/produkte/mass-toepfe
On the second page on the form you can choose a color or enter a Number (bottom right).
Right now there is a standard validation on the colors which are a radio element.
I want to ask if it is possible somehow that when something is filled in the Number field that the radio element gets validatet.
Right now you get an error if you only type in a number, because no radio element is checked.

Thank you
#236457
  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Custom validation via other field

Hello,

If I understood correctly, how you want this to work is that if a number is entered in the Number field, that it is no longer required to select a color in the color radio group, am I right? So user should be able to submit the form without selecting the color.

If that is the case, you can simply add a condition to the validation script of the radio group similar to this:
if( ff_getElementByName('RequiredElementName').value != "") {
return "";
}
Which validation script are you using for the color radio group at the moment?

Regards,

Mihaela
#236461
  • Pascal Kurmann
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 95
  • Thank you received: 0

Pascal Kurmann replied the topic: Custom validation via other field

Hi Mihaela,

Yes you understood correctly.
Rigth now I use the ff_anychecked from the library.
Wouldn't I have to combine these two?
something like:
if( ff_getElementByName('RequiredElementName').value != "" OR if ff_anychecked
How would this code look like?

Thanks
#236462
  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Custom validation via other field

Hello again,

Yes, you have to combine the two, That is why I needed to know which script you are using so I can add the wanted condition to that script.

So, to achieve what you want, do as follows.

Go to Properties of that radio group element with colors that you wish to validate.
In Validation section of that element set Validation Type to Custom and in the code area below put the following code:
function ff_RADIOGROUPNAME_validation(element, message)
{
    if( ff_getElementByName("NUMBERFIELDNAME").value != "") { return ''; }
    var name = '';
    if(!element.name){
    	if(element.length && element.length != 0){
           name = element[0].name;
           var cnt = 0;
           for (var i = 0; i < element.length; i++)
             if (element[i].name==name) 
              if (element[i].checked) cnt++;                      
           if (cnt==0) {
            ff_validationFocus(element[0].name);
            if (message=='') message = "Please check or select "+name+".\n";
            return message;
           } // if 

        } else {
           return '';
        }
    } else {
      name = element.name;
      if (name.substr(0,6) == 'ff_nm_') name = name.substring(6,name.length-2);

      // loop through elements and count selections
      var cnt = 0;
      for (var i = 0; i < ff_elements.length; i++)
        if (ff_elements[i][2]==name) 
            if (ff_getElementByIndex(i).checked) cnt++;

      // if none selected, emitt error
      if (cnt==0) {
        ff_validationFocus(element.name);
        if (message=='') message = "Please check or select "+name+".\n";
        return message;
      } // if
    }
    
    return '';
} // ff_RADIOGROUPNAME_validation
NOTE: In the code above please replace both instances of RADIOGROUPNAME with the name of your radio group element that contains colors.
Also, replace NUMBERFIELDNAME with the name of the field where the name is entered.

Let me know whether you have managed to set this for your form and whether it is working as you wanted.

Regards,

Mihaela
#236471
The following user(s) said Thank You: Pascal Kurmann
  • Pascal Kurmann
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 95
  • Thank you received: 0

Pascal Kurmann replied the topic: Custom validation via other field

It worked!

Thanky you very much and have a nice day :)
#236472
  • Posts: 2461
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Custom validation via other field

Great!

I'm glad I've helped and that it worked. :)

Best regards,

Mihaela
#236475
Moderators: ForumSupporttomeperica
Time to create page: 0.042 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here