Page 1 of 1

Users lookup dropdown list

Posted: 2016-07-30 20:26
by bruceholt
I am trying to create a task assignment app but need to choose users from a dropdown list from the members table (not an additional addon table) and assign the task to them. I am not sure if this is possible using hooks or by some other method and if the permissions for accessing that table could be a problem. Has anyone managed to do this or knows how to do it?

Re: Users lookup dropdown list

Posted: 2016-08-09 15:02
by grimblefritz
You could create a field using the "Options list" tab. Enter bogus data for the options. That will result in a standard HTML <select> being generated.

Then, use jquery in the tablename_dv() hook to modify the <select> <option>s.

For instance, this is an example of the <select> code AG outputs, for a field 'userlist', not required, one option of ANY:

Code: Select all

<div class="form-group">
	<label for="userlist" class="control-label col-lg-3">Suffix</label>
	<div class="col-lg-9">
		<select style="width: 100%;" name="userlist" id="suffix">
			<option value="">&nbsp;</option>
			<option value="ANY" >ANY</option>
		</select>
		<script>jQuery(function(){ jQuery("#suffix").addClass('option_list').select2({ minimumResultsForSearch: 15, width: '90%' }); })</script>
	</div>
</div>
Your hook would need to fetch the users from the members table, then create the <option> tags, and then use jquery to replace (or append to) the <option> list generated by AG.

That's one way. Probably the simplest way. But, if you have a lot of users, then you might want to look into how to modify a regular lookup field, which is done using the select2 js library. Not as easy, but creates a much better user interface.

Re: Users lookup dropdown list

Posted: 2016-08-10 07:53
by bruceholt
Thanks very much for your help, grimblefritz. It gives me something to work on.

Re: Users lookup dropdown list

Posted: 2016-08-10 11:06
by grimblefritz
I should have finished cleaning up the code before posting. Here's a clean example.

Code: Select all

<div class="form-group">
   <label for="userlist" class="control-label col-lg-3">User List</label>
   <div class="col-lg-9">
      <select style="width: 100%;" name="userlist" id="userlist">
         <option value="">&nbsp;</option>
         <option value="ANY" >ANY</option>
      </select>
      <script>jQuery(function(){ jQuery("#userlist").addClass('option_list').select2({ minimumResultsForSearch: 15, width: '90%' }); })</script>
   </div>
</div>

Re: Users lookup dropdown list

Posted: 2017-02-14 13:35
by jsinason
Can you explain what you mean by

"
Your hook would need to fetch the users from the members table, then create the <option> tags, and then use jquery to replace (or append to) the <option> list generated by AG.
"

thanks

Re: Users lookup dropdown list

Posted: 2018-04-12 21:28
by pbottcher
Hi,
I tried to get this working, but am failling due to the error:
ajax' is not allowed for Select2 when attached to a <select>
when I try to have the data for the selection box polled via ajax.

Any ideas how to reslove this?

Re: Users lookup dropdown list

Posted: 2018-04-18 14:06
by R Tammam
Hello pböttcher,
you can change the select to div

Code: Select all

 <label for="userlist" class="control-label col-lg-3">User List</label>
   <div class="col-lg-9">
  [code]    <div style="width: 100%;" name="userlist" id="userlist">
<option value="">&nbsp;</option>
<option value="ANY" >ANY</option>

Code: Select all

    </div>
<script>jQuery(function(){ jQuery("#userlist").addClass('option_list').select2({ minimumResultsForSearch: 15, width: '90%' }); })</script>
</div>
</div>[/code]

Re: Users lookup dropdown list

Posted: 2018-04-18 14:06
by R Tammam
<label for="userlist" class="control-label col-lg-3">User List</label>
<div class="col-lg-9">
<select style="width: 100%;" name="userlist" id="userlist">
<option value="">&nbsp;</option>
<option value="ANY" >ANY</option>
</select>
<script>jQuery(function(){ jQuery("#userlist").addClass('option_list').select2({ minimumResultsForSearch: 15, width: '90%' }); })</script>
</div>
</div>