I have a form. It has a detail form linked to a grid application where all features are activated. In the grid application, new record would open in modal and this is where im having the problem whenever the select fields use Select2. select field do not show the lists to choose from.
Yep modal in SC can break Select2 elements.
If you can, change the grid so that the form is not open as modal.
Another workaround is to inject JS code to make the form reload once on load. Before doing that, manually test that a reload fix the issue (in Chrome you can right click on the modal form and select “reload frame”)
Note that the “reload” string is just an identifier.
I’m not 100% sure, but I think its’ safer if it’s unique, so if you use this code in more than one app you can customize it per app; e.g. using or adding the app name in it, instead of just ‘reload’.
so let me get this straight, if I understood correctly, let’s say I have a Grid application called “Grid_Items”, and on that grid there is a button that opens a modal to add a new record, the app that gets called in the modal is a Form called “Add_grid_item”.
So in my case, I should edit my “Add_grid_item” Form, which is the one opened in a modal,
and there add under Events -> OnLoad, this:
The string can be whatever you like, my suggestion is to use a unique string per app so that’s why I’m using the app name.
E.g. you coud use “reload_Add_grid_item”. Or just the app name as you did.
Also note that what makes the JS code work at the right moment is the embedding in the JS window.onload event, so you could add that JS code event is the onScriptInit SC event instead of the SC onLoad event and it would still work
If you don’t want this reload event to occur when the form is not run as modal, you could embed all your code above in a check for a passed var and act accordingly.
E.g. pass “force_reload” = 1 when open as modal and pass nothing when open not as modal
thank you again for the help, I have one more question, you say the string can be whatever I like, but somehow it needs to point to my modal right? I mean, the string I put there must be referenced somehow, I thought this was done by putting a string that matches the application name, so the script knows what part to reload? If I just put a random string, how will it know what o reload? thank you again
That code has no notion of which “part” to reload, it will reload that same page where it’s run.
Being run inside an iframe (the modal form), it’s the iframe (the modal form) that will be reloaded.
The string can be a random string. It’s needed by that piece of JS code only and with no reference to anything else outside of it.
It’s needed so that the JS code won’t loop reloading itself (the page) forever.
As you can see, before reloading it will first check that an item with that string name is not true. At first run it won’t match and the item will be created and “location.reload()” will be executed.
But when the iframe page is reloaded, the JS code will be executed again, potentially looping forever.
But since this time the named item exists, the form will not reload again a second time (preventing the loop) and it will instead just delete the item.
The item is deleted so that when the form is loaded again manually (not by the code itself) the code-triggered reload can be executed again.
Also, maybe I’m too paranoic here and using the same string (e.g. “reload”) in more than one app won’t cause any issue.
I finally had the chance to try this workaround but I have a problem!
Basically when I put that script on the onLoad event of the application that gets loaded in the modal, what happens is:
I click from my main grid a button called “new item”, which opens the modal with my form application that has the onLoad event
But after I added this script on that event, when I Click “new item” button, it opens the modal for 1sec or less, and it closes it right away, then if I click again it will stay open! But the first time you click it will open and right away close the modal!
And if you wait let s say more than 10seconds between click, it will again open and right away close it!
The only way to keep it open is to click on the button, the modal will open and close, then you click right away again on the button, now the modal will stay open!
I m using Chrome as well, and I tried putting the JS code on onScriptInit and also on onApplicationInit but the behaviour is always the same.
To recap, I have a Grid that shows all the records,
then I have a button (custom button) called “New record”, so when clicked, it will open a form in a modal, where you can add a new record, and when you save the modal will close and the new record will be displayed in the grid.
This works really good in local, but in production, I will have the bug on the Select2 fields.
on the FORM (the one that gets opened in the modal when you click the button on the grid) and I tried the 3 events mentioned above (onSCript, onLoad, onAppInit)
what happens is, as soon as you click the button, the modal will open and close right away after less than a second.
But if you click right away again the button, the modal will stay opened.
If you click only once, when it closes right away, then you dont click for at least 10 seconds, it will autoclose again, the only way to keep it open is to click a second time on the button in less than 10 seconds from the first time you clicked and the modal got closed right away!
Maybe your issue is different than the one I solved with this workaround.
First of all, I get the same issue in both dev and in production, you get it only in production, right?
Second, before trying to use this workaround you should check if a manual reload of the frame in chrome fix it. Did you try it and did it fix ths select2 display issue? And when manually reloading the frame, do you have any of the weird effects you have with the JS code?
So I’ve been doing some testing, I don’t get this issue at all, neither in production or locally, but other members of the team are getting it in production! We all use chrome, and yes, a reload would fix it! And a reload is not even necessary, as soon as you click on the ADD button to add the record, it will says that required fields are missing (the broken dropdowns), then as soon as that message pops up, the dropdown are fixed, so there a reload happens when you click ADD and it fixes the problem.
This doesn’t happen with firefox or edge, only Chrome and only for some people, not for every machine we use
no, besides an automatic lookup to fill the dropdown, there is no additional code! We did more tests, and on most computers it works without issue, only a few have this problem! and it only with select2, but we need that one as the dropdown has around 200 entries, so a search option inside the dropdown is needed!
But if this is a bug I guess it will be fixed in a future update, for now it’s not deal breaking as only a few computers experience this