--- /dev/null
+(function( $ ) {
+ $.widget( "custom.combobox", {
+ _create: function() {
+ this.wrapper = $( "<span>" )
+ .addClass( "custom-combobox" )
+ .insertAfter( this.element );
+
+ this.element.hide();
+ this._createAutocomplete();
+ this._createShowAllButton();
+ },
+
+ _createAutocomplete: function() {
+ var selected = this.element.children( ":selected" ),
+ value = selected.val() ? selected.text() : "";
+
+ this.input = $( "<input>" )
+ .appendTo( this.wrapper )
+ .val( value )
+ .attr( "title", "" )
+ .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
+ .autocomplete({
+ delay: 0,
+ minLength: 0,
+ source: $.proxy( this, "_source" )
+ })
+ .tooltip({
+ tooltipClass: "ui-state-highlight"
+ });
+
+ this._on( this.input, {
+ autocompleteselect: function( event, ui ) {
+ ui.item.option.selected = true;
+ this._trigger( "select", event, {
+ item: ui.item.option
+ });
+ },
+
+ autocompletechange: "_removeIfInvalid"
+ });
+ },
+
+ _createShowAllButton: function() {
+ var input = this.input,
+ wasOpen = false;
+
+ $( "<a>" )
+ .attr( "tabIndex", -1 )
+ .attr( "title", "Show All Items" )
+ .tooltip()
+ .appendTo( this.wrapper )
+ .button({
+ icons: {
+ primary: "ui-icon-triangle-1-s"
+ },
+ text: false
+ })
+ .removeClass( "ui-corner-all" )
+ .addClass( "custom-combobox-toggle ui-corner-right" )
+ .mousedown(function() {
+ wasOpen = input.autocomplete( "widget" ).is( ":visible" );
+ })
+ .click(function() {
+ input.focus();
+
+ // Close if already visible
+ if ( wasOpen ) {
+ return;
+ }
+
+ // Pass empty string as value to search for, displaying all results
+ input.autocomplete( "search", "" );
+ });
+ },
+
+ _source: function( request, response ) {
+ var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
+ response( this.element.children( "option" ).map(function() {
+ var text = $( this ).text();
+ if ( this.value && ( !request.term || matcher.test(text) ) )
+ return {
+ label: text,
+ value: text,
+ option: this
+ };
+ }) );
+ },
+
+ _removeIfInvalid: function( event, ui ) {
+
+ // Selected an item, nothing to do
+ if ( ui.item ) {
+ return;
+ }
+
+ // Search for a match (case-insensitive)
+ var value = this.input.val(),
+ valueLowerCase = value.toLowerCase(),
+ valid = false;
+ this.element.children( "option" ).each(function() {
+ if ( $( this ).text().toLowerCase() === valueLowerCase ) {
+ this.selected = valid = true;
+ return false;
+ }
+ });
+
+ // Found a match, nothing to do
+ if ( valid ) {
+ return;
+ }
+
+ // Remove invalid value
+ this.input
+ .val( "" )
+ .attr( "title", value + " didn't match any item" )
+ .tooltip( "open" );
+ this.element.val( "" );
+ this._delay(function() {
+ this.input.tooltip( "close" ).attr( "title", "" );
+ }, 2500 );
+ this.input.autocomplete( "instance" ).term = "";
+ },
+
+ _destroy: function() {
+ this.wrapper.remove();
+ this.element.show();
+ }
+ });
+ })( jQuery );
{% csrf_token %}
<label for="authority_hrn" class="control-label">Organization</label>
<p></p>
- <input id="authority_hrn" name="org_name" class="form-control" style="width:590px" value="{{ organization }}"
+ <div class="ui-widget">
+ <select id="org_name" name="org_name" class="form-control" style="width:590px" value="{{ organization }}"
title="Choose your organization (company/university) from the list that apears when you click in the field and start to type.
Use the arrow keys to scroll through the list; type part of the name to narrow down the list. We will send an email to
- the managers that we have on record for your organization, asking them to validate your sign-up request." required />
+ the managers that we have on record for your organization, asking them to validate your sign-up request." required>
+ {% if authorities %}
+ {% for authority in authorities %}
+ {% if authority.name %}
+ <option value="{{ authority.authority_hrn }}">{{authority.name}}</option>
+ {% else %}
+ <option value="{{ authority.authority_hrn }}">{{authority.authority_hrn}}</option>
+ {% endif %}
+ {% endfor %}
+ {% else %}
+ <option value:"">No authority found !!!</option>
+ {% endif %}
+ </select>
+ </div>
<p></p>
<p>Organization not listed? <a href="/portal/join">Request its addition now.</a></p>
</div>
{% if authorities %}
{% for authority in authorities %}
{% if authority.name %}
- {value:"{{ authority.name }}",label:"{{authority.name}}"},
+ {value:"{{ authority.authority_hrn }}",label:"{{authority.name}}"},
// show hrn if we don't have the name
{% else %}
{value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"},
{% endif %}
];
// sorting the list
+
availableTags.sort(function(a,b){
var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase();
if (nameA < nameB) {
return 0;
});
// auto-complete the form
- $( "#authority_hrn" ).autocomplete({
- source: availableTags,
- minLength: 0,
- change: function (event, ui) {
- if(!ui.item){
- jQuery("#authority_hrn").val("");
- }
- }
- });
+ jQuery("#org_name").combobox();
$('[title!=""]').qtip();
$("form").validate();
$("form").submit(function() {