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

Question

Question

Forms - Drop-down - Choices

asked on April 11, 2014

 I have a Forms Drop-down populating from a Lookup Rule.  The Lookup Rule is using a stored procedure that returns LocationName and LocationCode.  A drop-down has the option to "Assign values to choices", but I don't see how this is done from the Lookup Rule.  I'd like the Drop-down to use LocationName for the display, but store LocationCode.   It seems as though I can only choose one field.

 

0 0

Answer

APPROVED ANSWER
replied on April 23, 2014

The Assign values to choices checkbox allows you to specify different values for each selection, but does not take variables and cannot be used with lookup rules. Could you split this into several rules?

 

1) Fill a drop-down with the location names.

2) When a location is selected, fill another field with the appropriate location code.

0 0

Replies

replied on July 20, 2016

It's been over 2 years since I posted this question originally and multiple new release of Laserfiche Forms but I still see this as an issue.  I'm wondering if this is on the development roadmap.  The basic function of every drop-down that I have worked with in other code is that there is a display string in the drop-down but a key value (record id, value code, etc.) is stored behind the scenes (not visible to the user).

Thanks,

Rob

1 0
replied on September 14, 2016 Show version history

I think that I finally come up with a solution for this issue.   The solution allows me to assign values to choices in a drop-down list from a lookup rule.   Below are the steps that I used.  I am using students (student number and student name) as my example.

  1.  Write a view/stored procedure that returns the value and the text that you want all in one field with some sort of unique separator between the two parts of the field. In this example I am using the pipe character (|) as the separator.
    (e.g SELECT '0001' + '|' + Jane Doe' AS [StuNoAndDesc])
  2. Create your lookup rule as normal, populating your drop-down list with the concatenated field.
    (e.g. Fill Student with result set column StuNoAndDesc)
  3. Use JavaScript to loop through all of the options returned by the lookup.  Split the field based on your delimiter character and assign the id value (StudentNumber) to the value option of the drop-down list and the description value (StudentName) to the text option of the drop-down list.

Here is a sample of the JavaScript: 

$(document).ready(function () {
  
	//Disable the Student Selector drop-down.
  	//Re-enable it later in the code after it has finished loading
  	$('.Field_StudentSelector select').prop('disabled',true);
  
    //This will attach an event that will only run once.
    //It will be run once ajax has completed
    //,which is when the lookup on a field has completed.
    $(document).one('ajaxStop',function(){ 
          //Loop through all options in the drop-down list.
          $('.Field_StudentSelector option').each(function(){
              //Split the text option on the pipe and take the first part
              //assign this as the option value.
              $(this).val($(this).text().split('|')[0]);
              //Split the text option on the pipe and take the second part
              //assign this as thetext value.
              $(this).text($(this).text().split('|')[1]);
          });
          //Re-enable the drop down now that it has completed loading
          //and had the option values and text set.
          $('.Field_StudentSelector select').prop('disabled',false);
      });
  
  //When a value (student) is selected get the
  //selected value from the drop-down and put into
  //the StudentNumber field.
     $('.Field_StudentSelector select').change(function () {
    	$('[attr=StudentNumber] input').val($(this).val());
  });
  
});

Here is sample of the outputted Html elements:

<ul>
  <li attr="teststudent" attrtype="select" name="q28" id="q28" class="Field_StudentSelector form-q label-left form-focused">
	<label class="cf-label" for="Field28">Student</label>
  </li>
</ul>
<div class="cf-field">
  <select id="Field28" name="Field28" aria-label="Field28" class="form-item-field cf-medium user-success" vo="e">
	<option value="0001">Jane Doe</option>
	<option value="0002">John Smith</option>
	<option value="0003">Zhang San</option>
	<option value="0004">Guiseppe Verdi</option>
	<option value="0006">Hans Schmidt</option>
	<option value="0006">Rajwinder Kaur</option>
  </select>
</div>

Thanks to Jonathan Rowe for pointing me in the right direction and for the tip about using ajaxstop as a method of ensuring that the drop-down has finished loading before processing the additional Javascript.  (more info in this post).

2 0
replied on April 11, 2014 Show version history

This is currently not available using a lookup rule as far as I am aware. I believe this feature has been requested though.

0 0
replied on April 14, 2014

Where can I go to submit feature requests, see what has been requested and vote for enhancements?

 

I've only been working with Forms for a couple of days, but it seems to be a bit buggy and missing some key features.

0 0
replied on April 14, 2014

You need to keep in mind that this is only the second release of Forms. Great features are being added with each release. To make a feature request just post it here in Answers and tag with Forms and Feature Request.

1 0
replied on April 14, 2014

Thanks a lot for the info.

0 0
replied on April 23, 2014

hi Rob,

 

What are the missing key features you refer to?

 

Thanks,

Abby

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

Sign in to reply to this post.