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

Question

Question

How to Change the List of an Input

asked on October 27, 2016

Hello,

In the attached image, I want to change the List parameter from datalistField20 to Field86. In the image, I used the Firefox debugger to manually change the List to Field86, to demonstrate what I'm after. I can't for the life of me find a solution on the 'net.

When I use $('#Field20').parent().html(), the value of list is "datalist20" so I'm unable to change the list value with a simple search and replace.

Has anyone got any good idea on how to achieve this?

-Ben

 

Capture.PNG
Capture.PNG (6.33 KB)
0 0

Answer

SELECTED ANSWER
replied on October 28, 2016

If I remember correctly, the list attribute is inserted into the input field when the lookup completes.

You probably have the $("#Field20").attr("list", "Field86") line inside your document.ready block (so it executes right when the form loads), but your lookups happen after that, so the attribute changes back to datalistField20.

You need to time it so that your code runs after the lookup completes.

0 0

Replies

replied on October 27, 2016

You could just use jQuery's attr function. $("#Field20").attr("list","Field86");

1 0
replied on October 27, 2016

Beat me to it. wink

0 0
replied on October 27, 2016 Show version history

Tried that, didn't work for me. Did it work for you?

Also tried

$('#q20').find('input').attr('list','Field86');

0 0
replied on October 27, 2016

I can't seem to change the list attribute. See the image.

 

Capture.PNG
Capture.PNG (8.49 KB)
0 0
replied on October 28, 2016

Okay, let's start from the beginning. Why are you trying to change the list attribute?

http://meta.stackexchange.com/a/66378/270325

0 0
replied on October 28, 2016

To make a searchable selection/drop down box with as little custom code as possible. I can make this happen with a stored procedure and a custom input box. Which is great for new forms but time consuming to retro fit to existing forms. If I can bind an existing drop down to a optionlist that is created by forms then I won't have to change the existing form.

 

 

 

 

 

 

 

 

 

0 0
replied on October 28, 2016

Regardless of what I'm trying to achieve, any idea why I can't change the list attribute?

0 0
SELECTED ANSWER
replied on October 28, 2016

If I remember correctly, the list attribute is inserted into the input field when the lookup completes.

You probably have the $("#Field20").attr("list", "Field86") line inside your document.ready block (so it executes right when the form loads), but your lookups happen after that, so the attribute changes back to datalistField20.

You need to time it so that your code runs after the lookup completes.

0 0
replied on October 28, 2016

Thanks! That looks good. Hopefully the attribute sticks. If not, that would be unfortunate but this answered my query. I placed the code inside

$(document).on("onloadlookupfinished", function () {

and it worked.

 

Now the text input has a list of options that dynamically updates, based on a stored procedure, using the input as the stored procedure parameter.

The benefit of this over the standard "Auto Suggestions" is the form doesn't have to be maintained everytime new people are added to the system, as a database lookup handles that.

The benefit over a standard drop-down is being able to type to filter.

You are not allowed to follow up in this post.

Sign in to reply to this post.