Replies: 2 comments
-
Hey @giovdi thank a lot for the suggestion. I really think this opens up the possibility to some really cool features, like showing avatars on user select lists etc. I am willing to give this a shot, there are some un-handled scenarios in your example that I am worried it could not work as I am expecting, for example the translatable selects. Can't promise any deadline, but I am moving this to the CRUD repository as a feature request because if it goes smooth on the scenarios we haven't tested yet, it will be an "easy" win for everyone. 👍 Once again, thanks for the suggestion. 🙏 Cheers |
Beta Was this translation helpful? Give feedback.
-
Hi @pxpm! Take your time to look over all the possibilities and scenarios (and potential issues). I know that this can take months; there's no rush. Cheers! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
Today, I was wondering if it's possible to write HTML into a Select2 dropdown with Backpack. Well, the short answer (I think) is no... but...
I tried looking at the code that generates the Select2 Javascript for my specific case, and it is probably pretty easy to do.
In this example, I added the following code blocks to
backpack/pro/resources/views/fields/relationship/select.blade.php
.At this point, I can add the following option to the CRUD:
CRUD::field([ 'name' => 'variants', 'type' => "relationship", 'inline_create' => true, 'init_rows' => 1, 'min_rows' => 1, 'subfields' => [ [ 'name' => 'price', 'label' => 'Price', 'type' => 'number', 'prefix' => "€", 'attributes' => ["step" => "any"], 'wrapper' => [ 'class' => 'form-group col-md-3' ], ], [ 'name' => 'weight_initial', 'label' => 'Weight', 'type' => 'number', 'suffix' => "grams", 'wrapper' => [ 'class' => 'form-group col-md-3' ], ], ], 'pivotSelect' => [ + 'html' => true, 'wrapper' => [ 'class' => 'form-group col-md-6' ], 'options' => (function ($query) { return $query->orderBy('variant_name', 'ASC')->get(); }) ], ]);
...and with the following accessor:
...here is the result!

Not so bad, isn't it?
As you can see from the code blocks, a
<span>
tag surrounds the HTML option, but you can customize it with thebase_element
property, as follows:'html' => ['base_element' => 'div']
.You can't avoid this because if you mix plain text options and HTML ones, the
$(elem.text);
fails with a JS error, so at least one HTML tag is required.Please let me know your suggestions... or if I just lost 2 hours of my life for some option that I don't know 😄
Unfortunately, I don't have enough time to create a full PR in a reasonable time, so please, if it's a good idea, take care of it :)
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions