Select2 strips out HTML tags

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Select2 strips out HTML tags

Post by jsetzer » 2019-03-28 16:10

This is not really a bug but rather request for help :? I'm not sure if this is the right forum. If not, please move this post.


Hi AppGineers,

we can use HTML to beautify the dropdown content of standard lookups. This works pretty well for selection. But after save and reload of the page the HTML fragments have gone. It seems as if SELECT2 strips HTML tags.

Please have a look at the Palette and Color fields especially after Save:
2019-03-28_16-51-58.gif
2019-03-28_16-51-58.gif (183.65 KiB) Viewed 2414 times

The dropdown content is pure HTML with some CSS. No images.

Questions
I have seen Select2's escapeMarkup-function. As this is not being used by AppGini's generated code, how can I late-bind this function?
Is there anything I can do with Select2 to keep the html-tags?


I really appreciate any kind of help!
Best Regards,
Jan

AppGini 5.75

PS: This is the HTML code inside the dropdown and after selection. That code gets stripped out after save / on reload.

Code: Select all

<span class="select2-chosen">
<span class="label label-default" style="background-color: rgba(166, 217, 106, 0.10); border: 1px solid gray;">&nbsp;</span> 
<span class="label label-default" style="background-color: rgba(255, 255, 191, 0.10); border: 1px solid gray;">&nbsp;</span> 
<span class="label label-default" style="background-color: rgba(253, 174, 97, 0.10); border: 1px solid gray;">&nbsp;</span> 
<span class="label label-default" style="background-color: rgba(215, 25, 28, 0.10); border: 1px solid gray;">&nbsp;</span> Diverging 4
</span>
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Select2 strips out HTML tags

Post by pbottcher » 2019-03-30 08:24

Hi,

as far as I could see it happens because AppGini uses a cache mechanisme and this converts the created html and replaces the " by &quot;

What you can try to do is

adopt in the ##TABLENAME##-dml.php file in the section

function ##FIELDNAME##_reload__RAND__(){

the

Code: Select all

text: resp.results[0].text
by

Code: Select all

text: resp.results[0].text.replace(/&quot;/g,"\"")	
or you could disable the cache by just returning false within the function in templates\##TABLENAME##-ajax-cache.php

Code: Select all

		cache.addCheck(function(u, d){
			if(u != 'ajax_combo.php') return false;
//			if(d.t == tn && d.f == '##FIELDNAME##' && d.id == data.##FIELDNAME##.id)
//				return { results: [ data.##FIELDNAME ], more: false, elapsed: 0.01 };
			return false;
		});
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Select2 strips out HTML tags

Post by jsetzer » 2019-03-30 10:35

@pböttcher
You are my personal SuperHero #1! :!:
Thank you for taking the time and precisely pointing me into the right direction.

Yes, it's a matter of caching. Your solution works like charm.

Instead of changing the template-code, which will be overwritten on next generation, I have found a slightly different solution which works better for me:

The file "templates/TABLENAME-ajax-cache.php" is responsible for setup of caching. If this file is not present, AppGini will not include it. Ergo: There will be no caching for this table. In this case this is OK for me, because there will not be too many records. I would avoid to disable caching in other scenarios. But here it's ok for me.

You can manually or automatically delete or rename that generated file(s). I'm automatically renaming the file...

templates/TABLENAME-ajax-cache.php

...into...

templates/TABLENAME-ajax-cache.generated.php

...in my _init function:

Code: Select all

function TABLENAME_init(&$options, $memberInfo, &$args){
    
    if (file_exists('templates/TABLENAME-ajax-cache.php'))
        rename('templates/TABLENAME-ajax-cache.php', 'templates/TABLENAME-ajax-cache.generated.php');
    
    return TRUE;
}

The dropdowns are being displayed perfectly now even after saving and reloading, see the green arrows:

chrome_2019-03-30_11-31-44.png
chrome_2019-03-30_11-31-44.png (127.68 KiB) Viewed 2382 times


Thanks again, @pböttcher, for all of your valuable posts here!

Best regards,
Jan

AppGini 5.75
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply