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

Question

Question

Forcing Selection from Single Line Lookup field

asked on August 31, 2020

I'm not sure this is possible, but wanted to ask.

 

In several forms, we have a Single Line field tied to a Lookup Rule listing all of our users. This allows the person filling out the form to select the person who the form should be routed to from the list that displays when they activate that field. We use a Single Line field for this instead of a Drop-down field because with Single Line, the choice list narrows based on what the user types into that field.

 

As an example, if I type "John" into the field, the choice selection narrows to show me both "John Smith" and "Mary Johnson." With close to 3,000 users on the list, this is an important feature, as it gives the user to ability to search by either first or last name. (with a Drop-down field, typing "John" would just move the user to the Js on the list, which we have sorted by last name - not nearly as nice)

 

Here's my question:

Is it possible to force the user to select the name from the list instead of just typing something into that field that doesn't match anything from the lookup?

 

To continue my example, if the user types "John" it narrows the list to anyone with "John" in their name, but if the user types "Johnxyz" there is no match.  Since we're using these fields for form/process routing, the process will suspend if this happens. We do use helper text, and we do have alerts to let us know when a process suspends so we can reassign manually, but it would be helpful to restrict the users so they are required to select the name from the list.

 

Again, I'm not sure if this is possible, but it would be GREAT if we could make this happen!

0 0

Answer

SELECTED ANSWER
replied on November 25, 2020

Okay, all set now!

Lots of trial and error, but here's where I've landed. The first code I posted (in the reply, above) gives you a blank line to select at the top of the drop-down, but doesn't display the placeholder text and the width isn't set.

With this code (below), there is no blank space. Instead, you get a tiny "x" next to your selection. This clears it out and displays the placeholder text again. With this code, the width is correct and the placeholder displays correctly.


/* Select2 Drop-Down User Selection */

    $('head').append('<link rel="stylesheet" href="https://forms.siumed.edu/Forms/js/select2.min.css" type="text/css" />');
    $(document).ready(function () {
        $('.table.cf-table-block').on('click', 'a.cf-table-add-row', ApplySelect2);
        ApplySelect2();
    });

    function ApplySelect2() {
      $.getScript('https://forms.siumed.edu/Forms/js/select2.min.js', function () {
            $('.employee select').select2({
            width: "450px",
            placeholder: "Select an employee",
            allowClear: true
            });
        });
    }
 

Thank you again for all of your help!

0 0

Replies

replied on August 31, 2020

My recommendation is to use a dropdown, but add a custom javascript dropdown control in the form of select2

 

Here is an example:

https://answers.laserfiche.com/questions/145237/Laserfiche-Forms-How-to-tie-a-field-to-a-database-table-column#145257

1 0
replied on September 1, 2020

Oooh!  That is nice!

 

I would be nervous about pointing to online code, though. The obvious problem being that if that site ever moved or changed, our code would break.

 

We're going to take a look and see if that's something we could write locally.

 

Thank you for the suggestion!

0 0
replied on September 1, 2020

That is a very good concern to have and is something we do for most of the times we deploy it. You can self host all that javascript and css as well.

1 0
replied on November 25, 2020

Has anyone tested the Select2 jQuery with Forms 10.4.5 when multiple conditions are required for the lookup to run? We had been using Chosen jQuery, but it no longer works with Forms 10.4.5.

1 0
replied on November 25, 2020

We have been using Select2, as described above, for all of our user lookups on Forms for several months now.

 

We've noticed, however, that there is no blank space at the top of the list for clearing out selections. In a normal drop-down, there is always a blank at the top, so if you decide the value entered wasn't correct, you have a way to clear it.

 

Is it possible to modify the Select2 javascript to include this blank?

 

I know we could include a checkbox for "clear selection" but our forms are already getting a bit bogged down with all of the code behind them, so I'd like to avoid adding much more if possible.

 

(if asking in this comment section of an old post doesn't get much visibility, I may make a new post for this question)

 

Select2 javascript:

 


/* Select2 Drop-Down User Selection */

    $('head').append('<link rel="stylesheet" href="https://forms.siumed.edu/Forms/js/select2.min.css" type="text/css" />');
    $(document).ready(function () {
        $('.table.cf-table-block').on('click', 'a.cf-table-add-row', ApplySelect2);
        ApplySelect2();
    });

    function ApplySelect2() {
      $.getScript('https://forms.siumed.edu/Forms/js/select2.min.js', function () {
            $('.employee select').select2({
                placeholder: "Select an employee",
                width: "450px"
            });
        });
    }

 

0 0
replied on November 25, 2020

Change your options to add allowClear:true.

            $('.employee select').select2({
                placeholder: "Select an employee",
               allowClear:true,
                width: "450px"

 

0 0
replied on November 25, 2020

Thank you so much!!!

 

That didn't do it, but it pointed me in the right direction and Google gave me the rest. I had to add two lines:

            data:data[$(this).val()],
            allowClear: true,

 

Here's the final JS that is working for me now:


/* Select2 Drop-Down User Selection */

    $('head').append('<link rel="stylesheet" href="https://forms.siumed.edu/Forms/js/select2.min.css" type="text/css" />');
    $(document).ready(function () {
        $('.table.cf-table-block').on('click', 'a.cf-table-add-row', ApplySelect2);
        ApplySelect2();
    });

    function ApplySelect2() {
      $.getScript('https://forms.siumed.edu/Forms/js/select2.min.js', function () {
            $('.employee select').select2({
            data:data[$(this).val()],
            allowClear: true,
            placeholder: "Select a value"
                width: "450px"
            });
        });
    }
 

I really need to spend some time learning Javascript...

0 0
replied on November 25, 2020

For some reason, the placeholder text isn't showing up now. I don't think that's a huge deal, but I clearly don't have it quite right.

0 0
SELECTED ANSWER
replied on November 25, 2020

Okay, all set now!

Lots of trial and error, but here's where I've landed. The first code I posted (in the reply, above) gives you a blank line to select at the top of the drop-down, but doesn't display the placeholder text and the width isn't set.

With this code (below), there is no blank space. Instead, you get a tiny "x" next to your selection. This clears it out and displays the placeholder text again. With this code, the width is correct and the placeholder displays correctly.


/* Select2 Drop-Down User Selection */

    $('head').append('<link rel="stylesheet" href="https://forms.siumed.edu/Forms/js/select2.min.css" type="text/css" />');
    $(document).ready(function () {
        $('.table.cf-table-block').on('click', 'a.cf-table-add-row', ApplySelect2);
        ApplySelect2();
    });

    function ApplySelect2() {
      $.getScript('https://forms.siumed.edu/Forms/js/select2.min.js', function () {
            $('.employee select').select2({
            width: "450px",
            placeholder: "Select an employee",
            allowClear: true
            });
        });
    }
 

Thank you again for all of your help!

0 0
replied on December 21, 2020

When I use this code and tie it to a field in a table, when adding a new row it does not bind to the new row and it shows as a normal select field. Any ideas?

1 0
replied on January 30, 2023 Show version history

It doesn't appear that someone had figured out how to make the single line work, so I ended up finding a solution. Here's how I did it - 

 

  1. Create a stored procedure to verify validation that the value exists in the database. This procedure will trigger as soon as the single line is filled in. 
  2. Create a hidden "output" field on the form that will show True or False based on whether the value exists in the lookup table. 
  3. Add a custom HTML field + JavaScript to show an error + hide the submit button when the validtion output = false. 

 

Here's some screenshots of each component. 

vendchknum is the field we are pulling on the single line lookup. I assigned that same field the @Vendor variable in the stored procedure. Then I'm filling the output of the procedure with the vndlookup column. 

 

Here's the form itself with the 3 fields. I used field rules to hide vendor_validation always but I save the data. Then I used field rules to show the custom HTML so the error is only visible when vendor_validtion = True

 

Finally, this little piece of JavaScript will show/hide the submit button depending whether the validation is true or false

 

 

Here's the actual code for your copying & pasting convenience

Stored Procedure

USE [LFFormsData]
GO

/****** Object:  StoredProcedure [dbo].[CheckProcVendorValidation]    Script Date: 1/30/2023 9:17:51 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[CheckProcVendorValidation]
@Vendor nvarchar(max)
AS

BEGIN 
	IF EXISTS 
		(SELECT vndchknm AS vndlookup FROM [GP].[UAIC].[dbo].[LaserficheActiveVendorLookup] 
		WHERE vndchknm = @Vendor) 
			BEGIN 
				SELECT 'True' AS vndlookup
			END 
		ELSE
			BEGIN 
				SELECT 'False' AS vndlookup
			END 
END
GO

JavaScript to hide Submit (replace q66 with the ID of your output field) 

  //Hide submit button if the vendor is not in the database
    $("#q66").on("change", "input", function(){
        if($(this).val() === "False"){
            $(".Submit").hide();
        }else{
            $(".Submit").show();
        }
    });

 

0 0
replied on February 23, 2023
	IF EXISTS 
		(SELECT vndchknm AS vndlookup FROM [GP].[UAIC].[dbo].[LaserficheActiveVendorLookup] 
		WHERE vndchknm COLLATE Latin1_General_CS_AS = @Vendor COLLATE Latin1_General_CS_AS ) 
			BEGIN 
				SELECT 'True' AS vndlookup
			END 
		ELSE
			BEGIN 
				SELECT 'False' AS vndlookup
			END 



			--COLLATE Latin1_General_CS_AS (this piece will check for case sensitivity in the string

One last note on the SQL procedure. If you need to add case-sensitivity for the string lookup, add the COLLATE commands

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

Sign in to reply to this post.