You are viewing limited content. For full access, please sign in.

Question

Question

How to compare field values is inside a Collector?

asked on August 30, 2023

I would like to verify if the Age in a numeric field is less than 16 years old, and if it is less, it will show a message as I have achieved in this example (that work for the first value, but not for the other if you add more):

$('#q74 input').on('change', function() {
     if ($('#q74 input').val() <= "15") {
              alert('Your age is under 16, you must be 16 or older to be a member.');
       $('.Submit').hide();
     } else {
       $('.Submit').show();
     }
   });
  
});

But if more fields are added to the collector, obviously the id of the field changes to #q74(1) or #q74(2), etc, as the number of records within the Collector increases, so that it could check this value in all the variants that the field can have?

Thank You

family-age.png
family-age.png (49.67 KB)
0 0

Replies

replied on September 5, 2023

Hi Luis,

You are right, the id will change as row grows.

You actually can set up a validation on forms. In age field, you can set Range allowed min to 16 

Then in error message tab, you can set your customized error message there when the age is less than 16. This will work for all rows in a collection

Hope that helps :)

1 0
replied on September 6, 2023 Show version history

Hi Yuxuan, your recommendation is great, but forget to mention that the Age field is filled in after the calculation of a formula that counts the years that have passed from the date selected in the Birthday Date field. and is on Read-only state. 
The formula I use is the following:

=IF(INDEX(Family_Members.Birthdate,ROW())="","",(DATEDIF(INDEX(Family_Members.Birthdate,ROW()),Todays_Date,"y")))

If I enter the Age manually, the error validation message that you suggest is displayed, but since it takes a formula, it does not detect, I create the event that the state of that field has been inserted or changed so that it performs the validation. I think I have to complement your solution with some detail that helps to refresh the values of the field once it is filled with the Age from the selected date or another. 

Any Idea? I will keep search a complementation solution who work together with your solution. 

age2.png
age2.png (41.06 KB)
0 0
replied on September 6, 2023

I see, since it's populated by formula and read-only, it will not be validated by min field and trigger error message unless you manually update it.

Just brainstorming, maybe you can try use a loop to loop through all rows in the collection and validate them? Below is an example for table, with collection you can try to replace it with <ul> and <li> stuff. But theoretically this will apply to all collections on your page

FYI I found this code in this post.

$('.tableClass').on('change', '.amount input, .state select', function() {
  $('.tableClass tbody tr').each(function() {

    let amount = $(this).find('.amount input').val();
    let state = $(this).find('.state select').val();

    $(this).find('.total input').val(ValidateRow(param)).change();
  });

});
1 0
replied on September 8, 2023

Thank you, let me try it. 

0 0
replied on September 8, 2023

Yuxuan, I have been trying to apply it but it doesn't work for me. There is a way which I think could be interesting to try, but I can't find the right way to do it.
For the method you proposed at the beginning to work, somehow the field to which I want to apply error validation must be in focus. So I think that a possible complementary solution could be to find a way that once the date field changes and the calculation is done in the Age field, the age field obtains the focus so that when the Focus changes the validation occurs. It could also happen when clicking on the Add more fields link in the collector, which first does a Focus or goes through the previous Age field first so that it validates the value and the validation of the error message can be executed.
I don't know, maybe I'm making my life too complicated in this detail, but there could be a way to solve it.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.