tractorcow / silverstripe-autocomplete Goto Github PK
View Code? Open in Web Editor NEWAutocomplete text field for Silverstripe
Autocomplete text field for Silverstripe
The moment I want to start a search, the browser crashes. Even a bare Chromium just stalls and sits there doing nothing.
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:
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"
This isn't really a fix for this bug but a grand vision for the future.
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?
Hey @tractorcow - just logging this is as a placeholder for SilverStripe 4 compatibility.
3
and/or 3.4
4.0.x-dev
upgrade
)The code documents each field as:
displayField
: The field or method used to identify the results.
AutoCompleteField
on the local object.labelField
: The field or method used for the display of the result in the listing.
However, the treatment appears to be:
displayField
is used as the value inside of AutoCompleteField
.labelField
.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).
Example 2: Stored field is "City", labelField is "FullTitle" (City + Country).
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:
labelField
) populates AutoCompleteField with the value from displayField
.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.
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.
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)
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
If I select an existing value from the autocomplete dropdown the value is saved to the database fine, but if I type in a custom value (or just type out a value that already exists in the dropdown instead of selecting it) the value isn't saved.
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)
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).
There are two three core issues:
null
.isset($this->sourceFields)
in ->getSourceFields()
will always return true
thus preventing a default from ever being set.->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
).
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:
What do you think? I suggest we either:
->setPopulateSeparately()
(my preference, and if so, maybe make this the default).->setClearWhenSelected()
and default this to true
.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.
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"
}
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')
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:
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.
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.
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.
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();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.