option force_selection=false not taken into account

Issue #31 new
Romain Deguy
created an issue

In jquery_autocomplete.js, if options has force_selection set to false, its value will still always be true (checked it via firebug using breakpoints).

I tried simulating a its value set to false by :

  • commenting self.element.val( "" ) at line 52
    Which effectively change the input's behaviour. If I press <tab> or click outside of it (which are considered focusout events) without selecting a suggestion, the text field is not cleared anymore.
  • changing the form submit function (l. 56)
this.element.closest( "form" ).submit(function() {
            if ( self.options.multiple ) {
                self.hidden_input.val( self.values.join(",") );
            } else if ( self.options.force_selection ) {
                //self.hidden_input.val( self.element.val() ? self.lastSelected.id : "" );
                self.hidden_input.val(self.element.val()); // set this so it will act just as if self.option.multiple is false and self.options.force_selection is false
            } else {
                self.hidden_input.val( self.element.val() );

At form submit, I am getting a django error invalid literal for int() with base 10: 'aboqavxwmz' as it seems it is submitting the autocomplete field instead of the item id. This is for a ForeignKey relation.

django admin screen

In this screenshot, Human has a ForeignKey to a Luggage. The autocomplete field is based on the Luggage.code field.

I am trying to achieve this so I can simply paste a string into the text box and press <tab> to go to the next field, instead of clicking on the suggestion first.

Comments (0)

  1. Log in to comment