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

Question

Question

How do you build a preference list?

asked on October 18, 2023

We were asked to create a preference list. I am trying to list 5-6 courses and they have to rank them in order from 1-6 without repeating. I was thinking about using a table with the courses listed on the left and 1-6 listed up top but I must be overlooking something. I can't figure out how to prevent them from listing everything as the first preference. Should I be doing this another way? How have you done it in the past?

 

In the end this will have to end up in a report saying Preference 1-6 and have the course listed below it. There will be no approval process.

0 0

Replies

replied on October 18, 2023

I have two main ways I handle this kind of stuff.

If you are in the Classic Designer, you can leverage Javascript for a variety of ways to do this, including custom elements that populate hidden LFForms fields.  The way I've done this in the past is a pre-populated table, with Javascript that lets you reorganize the rows of the table, it's more user friendly, but can be more complicated to set-up.

If you are in the Modern Designer, I would recommend using field rules to show a warning about duplicates and hide the submit button.  The rules get a little complicated, because you would need to have six drop-downs or radio buttons, and each one has a rule that says something like "1 doesn't match 2, and 1 doesn't match 3, and 1 doesn't match 4, etc." in order for the warning to be hidden and the submit button to be shown.  Six sets of rules, one for each of the six fields.

0 0
replied on October 18, 2023 Show version history

Here's a demonstration of a pretty easy to implement option in the Classic Designer.  This was tested on Version 11.0.2307.40547.

Add a table to your form with CSS Class of sortableTable.  Include a single line field in the table with CSS Class of sortableTableField.  Make sure the field is not readonly and you probably don't want a default value either.  Set the table to "Append rows to the rows populated by a data source or variable" with a range of 0 to 0 additional rows allowed.

Set-up a lookup rule to populate some list of values into the field in the table.  It doesn't need any conditions, but you probably want a relatively short list.  Be sure to check the box for loading them "as new rows".

Add this CSS to the form: 

.sortableULField {
    margin-top: 10px;
    margin-bottom: 10px;
    margin-left: 20%;
    margin-right: 20%;
    padding: 5px;
    border: solid;
    text-align: center;
    font-size: large;
}

 

Add this Javascript to your form: 

$(document).ready(function() {
  
  //Hide the table with the sortableTable class, it's just used to save
  //the values, and will be updated using another component.
  $('.sortableTable').hide();
  
  //Create the list of sortable elements when the form is loaded, when 
  //lookups are complete, and when changes to the sortableTable table happen.
  //Then manage the sortable element and update the table when the sortable
  //elements are dragged.
  createSortableElements();
  $('.sortableTable').change(createSortableElements);
  function createSortableElements() {
    $('#sortableULStructure').remove();
    var htmlStructure = '<ul id="sortableULStructure">';
    $('.sortableTableField input[type="text"]').each(function() {
      htmlStructure = htmlStructure + '<li class="sortableULField">' + $(this).val() + '</li>';
    });
    htmlStructure = htmlStructure + '</ul>';
    $('.sortableTable').after(htmlStructure);
    $('#sortableULStructure').sortable();
    $('#sortableULStructure').on( 'sortupdate', function() {
      var childCounter = 0;
      $('.sortableULField').each(function() {
        $('.sortableTableField input[type="text"]:eq(' + childCounter + ')').val($(this).text());	
        childCounter++;
      });
    });
  }
  
});

//When lookups are complete, trigger a change which will trigger
//other changes with the other code.
$(document).on('lookupcomplete', function() {
  $('.sortableTable').trigger('change');
});

 

The end result will be a list of values in a format that can be dragged around in priority order, and the values will be saved in the fields.

However, be aware that the code isn't optomized for read-only version of the form, so if displayed read-only or archived to the repository, it won't display as expected.  For read-only or archival, you should have an alternate version of the form without the Javascript, and with the actual table formatted how you'd like.

1 0
replied on February 13, 2024

This is cool.  How would I accomplish this with a Tablet and Chrome Browser ?

0 0
replied on February 14, 2024

Is the preference ranking dynamic? does it change as registrants apply, or is the preference list a static list?

I am not a javascript guy at all, so here are some options that I would follow based on my requirements:

  • If it is dynamic, and always changing by the amount of registrants I would have workflow input registration details to a table and then have the optional list promoted as a lookup from a db view; that db view can then be catered to what is needed (top 6 by count of records) to always provide the most up to date list into a form.
  • If it the list is static what would be wrong by naming the list "List of XXX in ranking/ranked" and then have the options be 1st XXX, 2nd XXX, 3rd XXX, etc...

 

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

Sign in to reply to this post.