Making Text Control Data Available for Ribbon Button Click
-
Thursday, May 10, 2012 12:16 AM
BACKGROUND
I have written a function which takes a block of text which has been pasted in a multi-line text control and parses it into the appropriate fields in the Contact form. With some help from some contributors here, the function now works very well.
I call the function from a custom button on the ribbon. So the desired sequence is that the user copies the text from the website we frequent, pastes it in the multi-line text control and then clicks the parse button on the ribbon.
PROBLEM
The problem is that nothing happens when the button is clicked. Evidently when the text is pasted in the control, it is not available until after the user moves focus away from the control. If I do this manually (click another control after the paste), it works correctly every time.
QUESTION
Is there a way in my code to force the pasted data to become visible so the user does not have to manually move the focus with another mouse click? I have tried doing a SetFocus on another control prior to loading the pasted text but that does not seem to help.
Thanks for any help.
All Replies
-
Thursday, May 10, 2012 8:00 AM
The problem might be in the programming behind the button. If you can maybe add some automatic page refreshing or even save and reload the page it might help.
Sounds to me like the problem is with an on change event. The on change event is only called after the user moves focus away from the control - that is how it knows that there was a change.
Please vote if you find my post useful. Add me on Skype @ christo.skype1
-
Thursday, May 10, 2012 1:41 PM
I think you are right about the requiring an OnChange event on the text filed before the data can been seen. The question is how to make that happen in code prior to try to load the text.
So far if have tried using setFocus on another field on the form and fireOnChange to force an OnChange event and make the data available. Neither appears to work. If others think either of these solutions should work, please let me know and perhaps offer some sample code.
I have never been able to get setFocus to work in CRM. Perhaps I'm doing something wrong and as I have a number of places I would like to use this.
I do not know how to do the page refresh you mention in code. Any coding help would be appreciated.
Thanks.
-
Friday, May 11, 2012 1:18 AM
Kahuna,
Can you try using setTimeout for your setFocus?
If you call your setFocus on the OnLoad event, sometimes it happened before the whole page is fully rendered which causes it to not work.
I hope this helps. If my response answered your question, please mark the response as an answer.
Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits
- Proposed As Answer by Dimaz Pramudya (www.xrmbits.com) Friday, May 11, 2012 1:18 AM
-
Friday, May 11, 2012 1:35 AM
Thanks Dimaz.
I asctually seem to have this working now. This code seems to work:
var fn = Xrm.Page.ui.controls.get("firstname");
fn.setFocus(true);whereas this code (which I used previously) does not:
Xrm.Page.getAttribute("new_reoprofile").SetFocus(true);
Although the latter does not cause an error, it just does not work.
- Edited by Kahuna2000 Friday, May 11, 2012 1:39 AM
- Marked As Answer by Kahuna2000 Friday, May 11, 2012 3:15 AM