-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local value support (Non Ajax local choices) #68
Conversation
I tried this but there is a bit of a problem. I haven't put anything in choices so it's null so I guess should work as normal via ajax. My form is not showing the existing values. The elements still work in that I can start typing and it displays the list from ajax but the value is not being displayed when select2 is not "open". I have a test form like this with two multiples and one single. Apply your patch, refresh and ... |
@tetranz Hmm sorry about that... <option value="{{ id }}" selected="selected">{{ label }}</option> It might be a bit more complex than this though... Would you mind sharing your test data so I can fix it on my end? |
No problem. I'll try it tomorrow. Yes, you're right, we could do with some
proper tests. Unfortunately I don't have much free time right now.
…On Sat, Feb 18, 2017 at 10:39 PM, Schyzophrenic ***@***.***> wrote:
@tetranz <https://github.com/tetranz> Hmm sorry about that...
To be honest I was wondering whether we should have a test part for this
bundle with a test page trying the different cases...
Can you try to replace the option value in fields.html.twig?
<option value="{{ id }}" selected="selected">{{ label }}</option>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACwj1esTc7jNzJLS1i6lYF8eg1a8X29xks5rd7l6gaJpZM4ME-xl>
.
|
@tetranz Let me know if I can help (and how :)) |
Unfortunately that didn't help. choices is null in the template. If I get some time I'll try to do some debugging. |
The problem is simply that for remote data, the select needs to iterate over I guess we could do |
Sorry to interrupt, is the point of this PR to display a list of options before the user start typing in the field? |
@tetranz , Would that make sense to just add a Controller and some views to test the rendering of the elements (plus potentially some automated tests)? Let me know if you would like to get this included in the bundle. That might be helpful to validate the PR as well :) |
Any update on when would this request be merged? |
I left a comment and then deleted it. I thought it was talking about something that had been merged. To answer the question, when will it be merged? Unfortunately, this PR doesn't work. It kills the ajax behavior and, as @mitch10593 points out, it removes good working code. Unfortunately I don't have time to fix it. I'm happy to merge a PR to include local value support provided it doesn't break other functionality. |
I'm surprised that local value support is such a sought after feature. Maybe I'm missing something but isn't it just as easy to use a standard choice field and one line of Javascript / jQuery to add the Select2 goodness? |
@tetranz In reaction to your last comment, may I reiterate my question: |
I don't know for the others so I'll speak for myself.
I wanted to have one single form type so I can easily move from Ajax to
local.
Additionally, and more importantly, I wanted local support to use the tag
feature allowing to add a new value.
Le 28 mars 2017 11:45 PM, "neFAST" <[email protected]> a écrit :
… @tetranz <https://github.com/tetranz> In reaction to your last comment,
may I reiterate my question:
is the point of this PR to display a list of options before the user start
typing in the field?
Is this PR the only way to do that?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABHrz995OobIomC6KfxS_ASkfkzvlbUrks5rqSsugaJpZM4ME-xl>
.
|
any update on this one? it would be nice to display a list of options before the user start typing in the field. |
You can work around this by setting minimum input length to 0. Or add an option 'default_choices' to the AjaxEntityType locally and extend the javascript method as documented. Other than that, you'll have to wait for a merge. Which won't happen until the PR is fixed. |
I'll try to take another look at this this week. Last time I tried it (long time ago now), it broke existing functionality. I can probably deal with the merge conflict if that's the only problem but I think it's more than that. I'm happy to include this feature if someone comes up with a PR that works without breaking BC. |
Looking at the code, this actually looks like it's meant to support ONLY local values, not in combination with the ajax. What the hell? That's not what the bundle is for. If you want select2 fields, just override Symfonys EntityType widget and pass the 'choices' option in the FormBuilder there. If anything, I feel like this PR should be changed in the way that it adds the functionality of default choices (before the user started typing) to be passed with a 'default_choices' option or similar. |
Okay, so if someone wants select2 functionality for just local choices, simply override the choice_widget in Form/fields.html.twig (corresponds to ChoiceType, which is the parent of EntityType).
and then call select2 in your javascript:
and that's it. You don't need this bundle. Edit: you can alternatively override just the EntityType widget, or create your own Form type with EntityType as a parent, for which you then override the widget. Edit: Coming to think of it, you literally only need the javascript code and add a EntityType field like this:
|
This PR is no longer relevant |
New Feature: Support of non Ajax field type
This PR is linked to the Feature Request #23. I give it a try and it seems to work OK in my current project.
Please note this PR is based on my previous one adding "tag: support for single entity (#67).
Let me know if you need anything else.
I hope you will have time to merge these requests soon as I am getting further away from your base code, and would like to avoid maintaining a separate branch :)
PS: Any comments on the code are welcome