Coder Social home page Coder Social logo

silverstripe-autocomplete's People

Contributors

assertchris avatar barry-bookinglive avatar camfindlay avatar christopherdarling avatar clodeindustrie avatar colymba avatar hudhaifas avatar jacobbuck avatar jcop007 avatar jonom avatar mfendeksilverstripe avatar muskie9 avatar nyeholt avatar patricknelson avatar robbieaverill avatar satrun77 avatar tractorcow avatar undefinedoffset avatar wilr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

silverstripe-autocomplete's Issues

Browser crashes

The moment I want to start a search, the browser crashes. Even a bare Chromium just stalls and sits there doing nothing.

BUG: Multi-word search terms

In a multi-word search term only the final word is used in a search, due to this loop within a loop, which keeps overwriting the previous filters: https://github.com/tractorcow/silverstripe-autocomplete/blob/master/code/AutoCompleteField.php#L495

Due to the limitation documented here: silverstripe/silverstripe-framework#1378 I'm not sure the intended effect can be accomplished with a single filter expression.

Additionally if the intended behaviour worked, typing more than one word would have the effect of increasing the number of matches instead of narrowing them down, which is counter-productive.

I have a few different ideas for fixing this:

1. The easy 'literal' way

Since this is billed as an 'auto complete' field rather than a search field it may be a better default behaviour to match on the full literal string rather than splitting up the string and treating each word as a key word. It's very easy to patch in the behaviour and works well for what I was trying to use this field for. Potential limitation is that if you've set the field to search across multiple fields, you can't enter a keyword that will match on one field and then a separate keyword that will match on another field, so you can only effectively search one field at a time. That could be made clear with some descriptive text on the field though e.g. "Type a Member name OR Company name"

2. The complex 'fuzzy' way

  • Split up search term as keywords as per original intention, but also include the complete search term in the array, so a literal match is possible
  • Make a separate results list for each field being searched, assigning a score to each record according to how many keyword matches were made. Sort based on Score DESC so more keyword matches = higher in the list.
  • Merge the lists and where a record is in more than one list, combine the scores. Return only the highest-scoring records

3. โšก๐Ÿ’ฅ ๐Ÿ”ฅ The ultimate has one picker field ๐Ÿ”ฅ ๐Ÿ’ฅโšก

This isn't really a fix for this bug but a grand vision for the future.

  1. Choose either of the previous methods for improving the auto-complete search algorithm
  2. Add pagination or a 'Load more' button to the results list
  3. Distinguish a search term from the stored value by using placeholder text to indicate the stored value
  4. When blurring the text field, clear the search term if a record wasn't selected so the stored record can be seen again
  5. Add a 'x' clear selection button for clearing the has_one relation
  6. Add an 'Advanced search' link which loads a detailed search form akin to GridFieldAddExistingSearchButton for when you can't find what you want with auto-complete.

Can you guess which solution I like best? This would be an asset for the project I think, but given how critical this bug is I think it would be best to start with the first solution, then maybe implement the second as time permits, then make a frankenstein ultimate has_one field once those pieces are in place (if they ever are).

Thoughts?

Holder: SS4 compatibility

Hey @tractorcow - just logging this is as a placeholder for SilverStripe 4 compatibility.

Pre-requisites

  • Branch current master off to 3 and/or 3.4
  • Update composer alias on master to 4.0.x-dev

Requirements

  • Add namespacing including upgrader
  • Implement core namespacing throughout (upgrade)
  • Tweak framework changes and/or CSS/Javascript selectors
  • Update template locations, tests, CI configuration, composer configuration
  • Update documentation/readme

Inconsistent treatment between "displayField" and "labelField"

The code documents each field as:

  • displayField: The field or method used to identify the results.
    • To me this is the field on the foreign object who's value is used to present what was selected and populates inside of AutoCompleteField on the local object.
  • labelField: The field or method used for the display of the result in the listing.
    • To me this means the field on the foreign object who's value is used to present an option in the suggested list prior to selection.

However, the treatment appears to be:

  • โœ… On initial form load, the displayField is used as the value inside of AutoCompleteField.
  • โœ… Suggestions listed during typing are pulled from labelField.
  • โŒ Selected value (from suggestion list) inserted into AutoCompleteField value is pulled from labelField instead of displayField as expected.

To me this is unexpected behavior, as ultimately the value used to populate the contents of AutoCompleteField should be consistent not only on field initialization, but also after interaction as well. Once you save, it initializes again with displayField's value.

Example 1: Stored field is "City", displayField is "FullTitle" (City + Country).

displayField

Example 2: Stored field is "City", labelField is "FullTitle" (City + Country).

labelField

Workaround:

Currently, the workaround required for consistency is to define both ->setDisplayField() and ->setLabelField() to the same field, which may not be obvious to a developer using this module until they've noticed that problem, takes the step to investigate and then takes action.

Possible fixes for consistency:

  1. Ensure that your selection from the suggestions (who are labeled via labelField) populates AutoCompleteField with the value from displayField.
  2. Eliminate these two fields and just use one (e.g. settle either on displayField or labelField).

Personally I would prefer option 2, because I would expect the suggestion I select to always populate into the field and should consistently remain in the field on save and etc. I'm not sure what the use case is for keeping them separate. But if we do keep them separate, their function should be clearly defined and they should function consistently.

Error with SS 3.2.0 beta 2

Just a head's up that the silverstripe-autocomplete module doesn't quite work with SS 3.2.0 b2. I get the following PHP Error Log:

PHP Catchable fatal error: Argument 1 passed to AutoCompleteField::Suggest() must be an instance of HTTPRequest, instance of SS_HTTPRequest given, called in /framework/control/RequestHandler.php on line 288 and defined in /silverstripe-autocomplete/code/AutoCompleteField.php on line 231

Stranger still when looking at line 231 the Suggest function appears to be passing a HTTPRequest anyway.

I just wanted to test a large Silverstripe site with the new 3.2 beta incase there were any issues and this is the first one I came to so I thought I'd report it. Still getting to grips with the many changes. Looks like a big release.

Improperly cleared if focus initializes on AutoCompleteField

If you place your cursor in AutoCompleteField and then either submit your form or refresh the page, the field will maintain focus. When the page initializes with the cursor placed inside of AutoCompleteField in both situations, blurring focus (moving the cursor anywhere else) will result in the field being cleared, even if it contains valid data.

This appears to be an artifact of the change event (registered in $input.autocomplete) being fired incorrectly, even though nothing has been changed. As a result, updateField() is called and the logic in that function then subsequently clears the field. This may be a deeper issue in the jQuery UI field, so can anyone else reproduce this bug?

What's happening in the GIF (and steps to reproduce)

  1. Create new DataObject, selecting an option (e.g. "Berlin") and saving
  2. On form load, cursor is still in field. Click outside of it. The field will clear (even though it hasn't changed)
  3. If you reload the page with cursor still inside field, field is re-focused. Click outside of field will clear it as well.

ezgif-4-954ec292219e

Add hooks to update returned item data

At the moment you can only return a single database field which prevents you from knowing immediately which ID or DataObject this field belongs to.

Adding the hook would allow more complex structures to be returned. This would leave the dev with the job of blocking the AutoComplete.js and creating their own, but would add more flexibility.

See here regarding returned data: http://jqueryui.com/autocomplete/#custom-data

Doesn't work within a AssetFormFactory

Trying to add the ability to attach tags to a File using the Autocomplete Field. While the input shows up, no javascript is present. Including the javascript on the page manually results in
this.source is undefined

screen shot 2018-09-14 at 1 27 31 pm

Can't clear selection

By default, it doesn't seem possible to clear the selected record, i.e. set it to ID=0. If you delete the text in the field and hit Save, the value reappears on select.

To make this behaviour possible you can do $field->setRequireSelection(false) but that leads to an error upon save if you type text in the field but don't choose a record. (ERROR [User Warning]: DataObject::get_by_id passed a non-numeric ID)

BUG: Performs partial match only on the *last* keyword separated by a space.

For some reason, this is splitting the query into multiple keywords, but then because of how it applies these keywords using the $filters array (https://github.com/tractorcow/silverstripe-autocomplete/blob/master/code/AutoCompleteField.php#L503) it only ends up applying the very last keyword. So, for example: If you searched for test abc it will only perform a partial match on "abc" not the AND combination of both test and abc like I think it should.

Also, while I'm here: How do you ensure the PartialMatch filter uses AND logic and not OR? It seems I cannot easily figure out how to pass an array into a filter to combine multiple possible values for a column this way. Seems like another totally separate issue, if it's not possible (either in code or in documentation).

Source fields initializing incorrectly.

There are two three core issues:

  • The source fields parameter in constructor should default to empty array, not null.
  • The check on isset($this->sourceFields) in ->getSourceFields() will always return true thus preventing a default from ever being set.
  • Assuming ->getSourceFields() returned a default, the field name is for the current field, not the field you're searching. So, as it's currently written, it could easily result in a database query error.

Impact: The end result is that it's not possible to leave that field blank, even though the way it's written, it implies it is optional. Leaving this blank results in an error deep in the framework ultimately caused by the filter in this module defining a ->filterAny() entry with a key exactly equal to :PartialMatch (due to the $sourceField being null and coercing to an empty string).

Affects: Appears to affect 3.5.2 and 4.x (or dev-master).

Bug/Feature: Since Autocomplete shows selected item, it should clear text field if selected.

Right now if I search for an item to select in autocomplete, it no longer autocompletes. It now is more of a search field (due to changes that have happened since 3.4.0 and now just recently tagged as 3.4.1). I noticed this when I updated my code so that I could submit PR #33.

If it works as a true autocomplete, it should automatically populate the field with the selected value. But since it no longer does that and instead just populates some text below the search field, this should either be considered:

  • A bug, since it doesn't follow the spirit of the name, or
  • I think it should clear the field once selected.

What do you think? I suggest we either:

  1. Add an option to have older functionality (populating selected text into auto-suggest field),
    e.g. ->setPopulateSeparately() (my preference, and if so, maybe make this the default).
  2. Clear the field once a selection is made.
  3. Add an option to clear the field once a selection is made, e.g. ->setClearWhenSelected() and default this to true.
  4. All of the above.

On focus selection

Hello,
I'm not sure if it is me using it in the wrong way or if this could be improved, but $('.field.autocomplete input.text') it is not returning/selecting anything.

I changed it to be:

        $('form').on('focus', 'input.autocomplete.text', function(e) {

        var input = $(e.target);

does it make sense or do you think it is now too generic?

The class of my autocomplete field is just class="autocomplete text" and there is no parent element having the field class.

Thanks.

[User Error] DataList::create Can't find data classes (classes linked to tables) for .

I hope this is a user error. :) When I remove all references to AutoCompleteField this error does not occur. Please find the full stack trace in the attached pdf (sorry github doesn't allow html uploads).

composer.json

{
    "name": "silverstripe/installer",
    "description": "The SilverStripe Framework Installer",
  "repositories": {
    "pocketrent/silverstripe-facebook": {
      "type": "package",
      "package": {
        "name": "pocketrent/silverstripe-facebook",
        "version": "1.0",
        "source": {
          "url": "https://github.com/gordonbanderson/facebook-auth.git",
          "type": "git",
          "reference": "origin/master"
        }
      }
    }
  },
    "require": {
        "php": ">=5.3.3",
        "silverstripe/cms": "3.2.*",
        "silverstripe/framework": "3.2.*",
        "silverstripe/reports": "3.2.*",
        "silverstripe/siteconfig": "3.2.*",
        "silverstripe-themes/simple": "3.1.*",
        "undefinedoffset/sortablegridfield": "^0.6.2",
        "silverstripe/multiform": "*",
        "burnbright/silverstripe-asmselectfield": "dev-master",
        "tractorcow/silverstripe-autocomplete": "^3.2",
    "pocketrent/silverstripe-facebook": "*",
        "silverstripe/restfulserver": "^1.0"
    },
    "require-dev": {
        "phpunit/PHPUnit": "~3.7@stable"
    },
    "config": {
        "process-timeout": 600
    },
    "prefer-stable": true,
    "minimum-stability": "dev"
}

cant_find_data_classes.pdf

Search across multiple fields not returning appropriate results

This issue was introduced after the fix for #32 was released.
We've got an autocomplete field which allows the user to search either firstname or surname in the autocomple field in order to find a member record. Since the query has been changed from filterAny to filter it will now only return a result if the keyword is in both the firstname and surname. e.g if you type "Jam" it will find Jamie Jamieson by not James Blunt.

AutoCompleteField::create('MemberID','Member','',null,null,'Member',array('FirstName', 'Surname')

Question using AutocompleteField in ModelAdmin filter fields

I've used AutocompleteField in both CMS and front-end forms and it works great. I'm looking to take it a step further and work it into a ModelAdmin filter fields. I've had mixed success as I've had to use the setSuggestURL() and can use the value that my front-end field used. The unfortunate part about this is it grabs the css files from the front-end (i.e. Form.css).

I figured out what would probably be the correct SuggestURL in the model admin but receive ModelAdmin::init(): Invalid Model class which would make sense. I guess I'm wondering if you have ever worked the field into the ModelAdmin filter area and/or if you know of a way to set that class on the type of call the field makes so the ModelAdmin would know what the managed model is.

Below is the full error:

screen shot 2014-12-09 at 2 16 53 pm

Pressing enter after editing the field does not save the field

My Setup

Had AutoCompleteField created with

  • setRequiredSelection(false)
  • setStoredField('Title')

I didn't want to store an the ID of the look up table. My lookup table only consists of the history of the field. The user may enter any value in the field or search/select from the lookup table.

Problem

  1. Entering the field and hitting enter key does not save the field

Troubleshooting

After some troubleshooting, I found that there is 2 post data with the same name (Name of the field) sent to the server.

I believe that one is hidden and one is for the display/functionality of the lookup field.

In AutocompleteField.js, there is 2 events (change, select) set up to updateField(), which I think populates StoredField into the hidden field, so it will be used for saving.

However, when hitting on enter, I think either the form was submitted before updateField was invoked or updateField wasn't invoked at all.

Work around

I have to hit on Tab to move the nexts field to force the event change and select that invokes updateField() before hitting Enter to save the form.

Autocomplete in the Frontend with Subsites

When use AutoCompleteFiield on the fronend with Subsite module; the autocomplete field in the frontend fails to call the Suggest function without the SubsiteID parameter included in the SuggestURL

public function getSuggestURL() {
        if (!empty($this->suggestURL)) {
            return $this->suggestURL;
        }

        // Attempt to link back to itself
        return parse_url($this->Link(), PHP_URL_PATH) . '/Suggest?SubsiteID=' . Subsite::currentSubsiteID();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.