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

Question

Question

Javascript validation not working on second item added in a collection on external link

asked on May 2, 2017

Hello,    

I used the following javascript code to apply a validation to a date field called Date of Birth, found in a collection. I created a css class called "dateofbirth".

//----------------------------------Performs code on load--------------------------------
    
    var todaysDate = new Date(); // Gets today's date 
    //Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly 
    var dob_year = todaysDate.getFullYear()-18; 
    //var dob_year = todaysDate.getFullYear();                        // YYYY 
    var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM 
    var dob_day = ("0" + todaysDate.getDate()).slice(-2);           // DD 
    var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date  
    // Now to set the max date value for the calendar to be today's date 
    $('.dateofbirth input').attr('max',dob_maxDate);
  
    $('#q53 > a').on('click',function() {

          //-----------------------Performs code when add button is clicked------------------------

          var todaysDate = new Date(); // Gets today's date 
        //Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly 
        var dob_year = todaysDate.getFullYear()-18;
        //var dob_year = todaysDate.getFullYear();                        // YYYY
        var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM 
        var dob_day = ("0" + todaysDate.getDate()).slice(-2);           // DD
        var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date
        // Now to set the max date value for the calendar to be today's date
        $('.dateofbirth input').attr('max',dob_maxDate);
    });

The code works perfectly in preview mode (means the ID used are correct). But when I published the form and tests it in an external link, it doesn't work in the second item of the collection. 


Note that we have a forms server in DMZ, used to publish forms over the internet. We are able to submit our form successfully. 

Please advise.

Best regards,

1 0

Replies

replied on May 3, 2017 Show version history

The issue does exist with Forms 10.2.0.834 and has been fixed in the coming Forms 10.2.1. You can modify it to be following to make it work with 10.2.0.834:

$(document).ready(function(){
//----------------------------------Performs code on load--------------------------------
    
    var todaysDate = new Date(); // Gets today's date 
    //Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly 
    var dob_year = todaysDate.getFullYear()-18; 
    //var dob_year = todaysDate.getFullYear();                        // YYYY 
    var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM 
    var dob_day = ("0" + todaysDate.getDate()).slice(-2);           // DD 
    var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date  
    // Now to set the max date value for the calendar to be today's date 
    $('.dateofbirth input').attr('max',dob_maxDate);
});
  
    $(document).on('click', '#q53 > a'),function() {

          //-----------------------Performs code when add button is clicked------------------------

          var todaysDate = new Date(); // Gets today's date 
        //Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly 
        var dob_year = todaysDate.getFullYear()-18;
        //var dob_year = todaysDate.getFullYear();                        // YYYY
        var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM 
        var dob_day = ("0" + todaysDate.getDate()).slice(-2);           // DD
        var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date
        // Now to set the max date value for the calendar to be today's date
        $('.dateofbirth input').attr('max',dob_maxDate);
    });

 

1 0
replied on May 2, 2017

Does it work in any of the collection fields if you've added 3, 4, 5, etc. records?

I just wonder if perhaps the code is processing before it finishes adding the row.  Thus when you add row 2, it can only run on row 1, but when you add row 3, it can run on rows 1 or 2.

0 0
replied on May 2, 2017

Same works in the internal link. This is why i cannot understand where the issue is, because the code execution is supposed to be the same on both external and internal. Correct me if i am wrong.

0 0
replied on May 2, 2017

It should be the same, but sometimes there are small differences to functionality between the different views of forms.

0 0
replied on May 10, 2017

Ok Thank you

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

Sign in to reply to this post.