TOPIC:

Custom validation via other field 1 year 1 month ago #236457

  • Topic Author
  • Pascal Kurmann
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 97
  • Thanks: 0
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

Please Log in or Create an account to join the conversation.

Custom validation via other field 1 year 1 month ago #236461

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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

Please Log in or Create an account to join the conversation.

Custom validation via other field 1 year 1 month ago #236462

  • Topic Author
  • Pascal Kurmann
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 97
  • Thanks: 0
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

Please Log in or Create an account to join the conversation.

Custom validation via other field 1 year 1 month ago #236471

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
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
The following user(s) said Thank You: Pascal Kurmann

Please Log in or Create an account to join the conversation.

Custom validation via other field 1 year 1 month ago #236472

  • Topic Author
  • Pascal Kurmann
  • Offline
  • Senior Breezer
  • Senior Breezer
  • Posts: 97
  • Thanks: 0
It worked!

Thanky you very much and have a nice day :)

Please Log in or Create an account to join the conversation.

Custom validation via other field 1 year 1 month ago #236475

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
Great!

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

Best regards,

Mihaela

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.050 seconds

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!