Problem/Motivation
When selecting a field in Entity has field condition it could be difficult to select proper one from a select list if there are hundreds of fields. If there were auto-complete field instead of select one, that would much better!
Proposed resolution
1) Define a new parameter called 'autocomplete' that you can use when defining context variables - this will be extremely similar to how 'options list' is defined and used, except that instead of declaring a function that returns options you declare a function to handle the autocomplete. This could then be used for any context variable, when desired - not just for field names.
2) Do something specific for field names. This would involve declaring a 'form_alter' callback for the specific condition/action that you're interested in, and in that 'form_alter' callback modify the form to do autocomplete instead of a select element. This would have to be done for each and every condition/action that you wanted to add autocomplete to.
Remaining tasks
Create Autocomplete variable
Create tests
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 1681494_6_0_Use_autocomplete_instead_of_select_list.zip | 8.22 KB | kellyimagined |
Comments
Comment #1
tr commentedMarked #2319403: Entity has field - Autocomplete for field list, as a duplicate.
Comment #2
kellyimagined commented@TR, can you give me a starting point of where I might find the settings in the module? I looked at previous tickets and did not see anything that could give a starting point. Once I have a starting point, I would be happy to dig into this and submit a patch.
Comment #3
tr commentedRules automatically generates the form elements used to enter values for context variables. Rules chooses the element type depending on the data type of the variable. In most cases this will be a textfield, and that can be used to enter strings, integers, floats, etc. In some instances, this will be a textarea - for example when you have bulk text or multiple values to enter. In other cases it will be a select element, if you've specified "options list" in your context variable definition - in which case there is also a function that you provide to return the list of options for the select.
In particular, there is currently no way for Rules to know that you want to use autocomplete instead of some other form element for one specific context variable.
So it seems to me there are two ways to approach this:
1) Define a new parameter called 'autocomplete' that you can use when defining context variables - this will be extremely similar to how 'options list' is defined and used, except that instead of declaring a function that returns options you declare a function to handle the autocomplete. This could then be used for any context variable, when desired - not just for field names.
2) Do something specific for field names. This would involve declaring a 'form_alter' callback for the specific condition/action that you're interested in, and in that 'form_alter' callback modify the form to do autocomplete instead of a select element. This would have to be done for each and every condition/action that you wanted to add autocomplete to.
I don't think this is especially hard. If you do #1, then you basically just have to cut and paste to duplicate what is done for 'options list' and then add some autocomplete stuff. But this DOES require adding test cases so that we can ensure it works and ensure it doesn't break existing sites.
Comment #4
kellyimagined commented@TR thank you for the information, I will look into this.
Comment #5
kellyimagined commentedComment #6
kellyimagined commented@TR I was looking more into this, and would like to propose the use of the chosen library.
Using this solution allows people to have the select they are used to as well as an autocomplete.
GitHub
Comment #7
kellyimagined commentedComment #8
tr commentedI'm not going to add a new module dependency this late in the D7 development cycle. I think people who want to use chosen can do that without any change to Rules.