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

Question

Question

Forms Dropdown created from Java Script

asked on July 25, 2014 Show version history

We have some javascript that populates a dropdown for possible dates for a new hire to start.  The drop down displays properly when submitting a form but the submission that is routed to the approver shows the selected date followed by the rest of the possible dates.

 

Here is the script that we are using:

$(document).ready(function () {
  $(".thisfieldreadonly input").prop("readonly", true);
  getMondays();
});
function getMondays(){
  var badMondays = [ '7/21/2014', '9/1/2014', '12/29/2014' ];
  var mondays = new Array();
  var maxWeeks = 12;
  var d = new Date();
  while(d.getDay() != 1){
    d.setDate(d.getDate() + 1);
  }
 
  while(maxWeeks >= 0){
    var m = (d.getMonth() + 1) + '/' + d.getDate() + '/' +  d.getFullYear();
    
    if(badMondays.indexOf(m) == -1){
      mondays.push(m);
      maxWeeks--;
    }
    d.setDate(d.getDate() + 7);
  }
 
 
  //FIND ELEMENT & SET VALUES
  //var dd = document.getElementById("XXXX");
  for(i=0;i<mondays.length;i++){
    $("#Field224").append(new Option(mondays[i], mondays[i]));
  }
}

 

Thanks, Jen

 

mod edit: You can use the code snippet option on the toolbar to make your code look nice. :)

0 0

Replies

replied on July 28, 2014 Show version history

Hi Jen,

 

I'm not sure what you mean when you say "but the submission that is routed to the approver shows the selected date followed by the rest of the possible dates."

 

I tried your script and it worked fine for me. I picked 9/22/1014 in the initial form. Here's what the approver sees:

 

0 0
replied on July 28, 2014

Can you provide a screenshot of the output you are getting on the approval side that you are trying to avoid? It will help us all understand exactly what your problem is.

 

I would double check to see if you have the javascript code on the approval form, it potentially might be causing complications.

0 0
replied on August 6, 2014

Hi Ege and Kenneth,

Here is how the Start Date looks as a user fills it out and submits it:

 

Here is what it looks like if you view the submission in Forms:

 

We would like only the date selected to be shown on the submission.  I have found that if the form is submitted using Google Chrome, it works fine.  However, some of their forms will be public facing so they won't be able to control which browser is used.

 

Thanks, Jen

 

0 0
replied on August 6, 2014 Show version history

Part of the issue is that your JavaScript is running each time the form is opened. Another issue is that these options will be added whether the form is read-only or not (it looks like in your last screenshot the form is read-only for that approval task).

 

You can get around that a couple of ways. If you are going to populate the drop-down when the form is first filled out, you can do it like this:

 

$(document).ready(function () {
  $(".thisfieldreadonly input").prop("readonly", true);
  
  if($('input[name="routingResumeId"]').val() =="") {
    getMondays();
  }
});
function getMondays(){
  var badMondays = [ '7/21/2014', '9/1/2014', '12/29/2014' ];
  var mondays = new Array();
  var maxWeeks = 12;
  var d = new Date();
  while(d.getDay() != 1){
    d.setDate(d.getDate() + 1);
  }
 
  while(maxWeeks >= 0){
    var m = (d.getMonth() + 1) + '/' + d.getDate() + '/' +  d.getFullYear();
    
    if(badMondays.indexOf(m) == -1){
      mondays.push(m);
      maxWeeks--;
    }
    d.setDate(d.getDate() + 7);
  }
 
 
  //FIND ELEMENT & SET VALUES
  //var dd = document.getElementById("XXXX");
  for(i=0;i<mondays.length;i++){
    $("#Field224").append(new Option(mondays[i], mondays[i]));
  }
}

I just wrapped your getMondays() function call in a statement to see if the form is at the first routing step (initial submission) or not.

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

Sign in to reply to this post.