Disable dependent picklist in visualforce page - javascript

I tried successfully to disable every input and select in my page:
$('input').prop('disabled',true);
$('select').prop('disabled',true);
But in my page I have two picklist, the second one is dependent from the first in SFDC.
And when I disable every select, the dependent is not disabled.
I try to hide it, but it doesn't work either!
It only works from the Console, but I need to put these controls in a Js function.

I've found that dependent picklists are not rendered on the page in time for code in a ready function to affect them. The only way I've been able to make changes to the dependent list is to do it in a setTimeout method that fires in 1000 milliseconds or so. It's not ideal, but it does seem to work.

Related

Jquery post issues

Ok, I'll try to explain this as best as possible.
I have a main html page with a dropdown. When the dropdown is clicked, the jquery loads another external html into a DIV on the page. There are a couple of dropdown items, so 2 different external htmls are being loaded into the same DIV depending on which dropdown selection was made. That works fine.
The issue I'm having is that on the additional html files that get loaded, I have some jquery that updates labels based on buttons or links clicked in the page. Everything works fine till I use the main dropdown to change the page/div selection, and then any jquery inside the additional HTML files seems to act multiple times, with the # of times equaling how many times the dropdown has been selected.
So for example, if I select "users" from the main dropdown, it loads an html with a list of users where I can remove or add new users and then add some groups to that user. The first time I load this template, things work fine. If I go back and reselect "users" from the main dropdown, now whenever I add a group or click a link to make user changes, it acts as if I have clicked it multiple times. If I reload the entire main page, this issue stops till I reselect the dropdown again more than once.
Is this an issue somewhere with jquery or could it be some other bug?
The fix was to add event.stopImmediatePropagation(); inside the click handler in the div template.
$(document).on('click',"[name=removeCategory]",function(event) {
event.stopImmediatePropagation();
...

How to fire CoffeeScript/Javascript after user presses back button

Different parts of the UI on my Rails 4 application rely on a dynamically populated select controls, where the option selected in the first select determines the options available in the second select. The script that sets the options of the second select runs when the select's onChange event is fired.
Everything works fine, until the user clicks the browser's back button and returns to the form that contains the two select controls. The first select retains the user's selection, but the second select (which is dynamically populated by the script) reverts to default options.
Browsers don't seem to fire any event at all when the user uses the back button, so there doesn't appear to be anything for me to hang my script on. How can I get my script to run after the user presses the back button?
What are my alternatives if I can't get the actual script to run? Do I have to ditch dynamic selects in favor of a single, massive select that lists all options in one control?
This is an inelegant, but expedient solution:
Rather than recreating my own session history mechanism, I just added a javascript_tag to my form which included a copy of the script which runs on page load (including when the user hits the back button, whereas the script in my assets folder only ran when the page was newly loaded).
This solution isn't DRY by any means, but it works in this limited circumstance.

Lotus Notes:Web page refresh restriction on attachment upload

I have a situation, in which I want to restrict my web page to refresh after I attach a document.
The secnerio is there is some hide when condition written on OnLoad of the Form using javascript, and as soon as the form loads the hide when is active but below that we have more hide when on the basis of selection of a drop down, that is also working, but if I attach a document the web page refreshes and the onload triggers, which further enables the first hide-whne and then again I have to select from drop-down to enable the next hide-when.
Please help if we can restrict web-page refresh after attachment upload.
It sounds like the problem might be more that you have to re-select the drop-down to get the hide-when on that to work after a refresh ? That is, the value is already selected, so there's no change, so the hide-when isn't triggered ?
If so, you probably need to package up the drop-down's hide-when code into a function (if it isn't aleready) and always call that during onload so that if the page refreshes, all hide-when is honoured.
That's assuming the hide-when resulting form the drop-down change is also in Javascript. If it isn't and you have "Refresh fields on keyword change" ticked in the Notes Designer field's properties, then that's what's causing the second refresh, and your best best would be to un-tick that peoperty and simulate the resulting hide-when using javascript, with an onchange event on the drop-down.

Is there a way to keep multiple select boxes open at the same time?

I have 2 Select Box in my HTML page.
For some reason, I wish to want both the text boxes open at the same time.
This may be for several purposes, like taking screenshots of the both open at the same time.
The problem I face is, when I click on one selectbox, another goes away, when I click on the other, previous goes away.
Is it possible to keep both the selectboxes open at the same time?
I am fine if it requires javascript to do so.
Here are the two boxes, which I wish to keep open, is it possible to block some events or anything?
Thanks
#xiankai: Yes I have considered using a list view already, and then later instructing that this would/could be a combo-box. Here's my work with this modification.
If your select box doesn't have many elements, have you considering using a listbox view instead? Simply add multiple to the your <select> element. Additionally, you can specify the height of the select box with the size attribute.

Is it possible to populate a SELECT dropdown when clicking on it?

I'd like to have a bunch of SELECT dropdown lists on my page which can be empty initially. When the user clicks on one of them, I want an AJAX call to be made to the server to get the desired list for the chosen dropdown. The results of this AJAX call are then put inside the dropdown and the dropdown then works as normal.
Is this possible to delay showing the dropdown list expanded until the AJAX call is complete? I have currently binded an event to the Focus event of each SELECT dropdown and that almost works, except the user is shown the empty list first. When they click away, the list then is populated with the results and works correctly from then on.
Ideally, I'd like it to say "loading..." when clicking on it, then replace this with the results without the user having to click away and then back again. Not sure if this is possible though.
I don't mind moving to a jQuery dropdown as opposed to the standard HTML SELECT in order to make this work.
Is this possible to delay showing the dropdown list expanded until the AJAX call is complete?
No. You don't get control over the internal behaviour of selects. Most browsers won't let you trigger an open click programmatically.
Consider using a faux-select made out of divs instead.
I think you have 2 options - 1 - make sure you fire the event after the AJAX call is complete, or fire the code that the event would call after the AJAX call is complete, or 2 - paut a setTimeout in the event and estimate the time it will take to make the call.
you can also cheat: onclick , substitute the options with one that just says "Loading..." and let it display normally. Then, when you have the correct data, you put it in the select and make it display the dropdown list again triggering the click event if necessary.
Does that make sense?

Categories