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

Question

Question

Name a table using variables

asked on October 4, 2017

I am working on a new form that requires a table.  I would like the table name to be dynamic according to previous data entered on the form.  I have...Time Sheet {/dataset/Month} {/dataset/Year}... written into the field label for the table.

When the information is entered on the form that relates to the datasets, the name does not change.  It just says "Time Sheet".  I was able to get it to work with Process Variables, but not Field Variables.

Is this possible?  I assume it is, because the variables are available.

I have included two screenshots below for illustration.

 

0 0

Answer

SELECTED ANSWER
replied on October 5, 2017

Hi Mary,

Try this:

$(document).ready( function () {
  var title = 'Time Sheet';
  var month = '';
  var year = '';
  $('#q1 input').on('change', updateTitle);
  $('#q2 input').on('change', updateTitle);
  function updateTitle () {
    var month = $('#q1 input').val();
    var year = $('#q2 input').val();
    $('#q3 .cf-section-header').text(title + ' ' + month + ' ' + year);
  }
  
});

q1: Field ID for month

q2: Field ID for year

q3: Field ID for time sheet table

Hope this helps.

0 0
replied on October 5, 2017

It worked, but the actual input of the month is a number (it is pulled from the start date). I have used to following code to assigned the text value for the month.

$(document).ready(function () {
  
   var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"];
  
  $('.start input').on('change', function() {
    var dateSplit = $('.start input').val().split("/");
    $('.startmonth input').val(monthNames[dateSplit[0]-1]);
    $('.startyear input').val(dateSplit[2]);
  });

When I use the code you provided, it still puts in the month in numerical format.  Is there a way I can have it populate the text value.

0 0
replied on October 5, 2017

Yes there is. Try this:

$(document).ready(function () {
  var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"];
  
  $('.start input').on('change',function() {
    var dateSplit = $('.start input').val().split("/");
    $('.startMonth input').val(monthNames[dateSplit[0]-1]);
    $('.startYear input').val(dateSplit[2]);
    $('.table .cf-section-header').text("Time Sheet" + " " + monthNames[dateSplit[0]-1] + " " + dateSplit[2]); 
  })
});

0 0
replied on October 6, 2017

Got it!

Thanks.

0 0

Replies

replied on October 4, 2017

I was able to do something similar using JavaScript. I created a var called Acceptance using the value i wanted to use in the title of the table  then used $('YOUR FIELD ID .cf-section-header').text(Acceptance); to assign that var to the title.

0 0
replied on February 4, 2020

You select the variable you want to use to name a field and then it just doesn't work?

 

 

Can someone from @████████ please explain what is going on here?

 

I don't want yet another flaky JavaScript workaround in my form.

0 0
replied on February 4, 2020
0 0
replied on June 22, 2020
<span data-bind-attr="variable">{/dataset/variable}</span>

You have the wrap the {/dataset/variable} in a data bind.  Then it will work!

 

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

Sign in to reply to this post.