This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Apr 20, 2011, 4:25 PM
10 Posts
topic has been resolvedResolved

Cannot Get Field Value From Inside Function

  • Category: Dojo and Client Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: client side JavaScript
  • Replies: 4
I'm having a problem obtaining the value from a field on my custom control through a function on the same custom control, and I'm absolutely baffled.  If anybody can please point out where my logic is incorrect and how I would obtain the value, that would be wonderful!  This is the last part of a solution I posted here for keeping the selected tab after an xPage document is saved or edited.  Now I'm trying to get the value of a unique item to tell it when NOT to keep the selected tab.
 
The name of the field I'm trying to obtain the value of is computedField2,  but it doesn't seem to matter what field or if the field is editable or computed as I've tried this with a bunch of fields on the custom control.  And the function itself is called by the onClick event of a dijit.layout.TabContainer on the same custom control.                                                        
 
 John Mackey had advised me that what I need is a client side solution, which works perfectly on everything else, so I've tried document.getElementById, getClientId, dojo.byId, and just about everything else I can think of, but I keep getting the message that the value either null or, the way I'm trying to obtain it is not defined.  I've even tried calling the compositeData item itself, but got the not defined message.  Here is the code:                                             
 
<script type="text/javascript">                                        
<![CDATA[                                                              
                                                                       
// This gets the tab the user is currently on, so we can set it when the user saves or edits the document                                   
dojo.require("dojo.NodeList-traverse");                                
                                                                       
function getTabName(e)                                                 
                                                                       
{                                                                      
                                                                       
// Lookup what tab the user is on                                    
        var tab = dojo.query(e.target).parents('.dijitTab')[0];        
        if (tab) {                                                     
                                                                       
        // As the widgetId contains the full path, we just want the tab id                                                                     
 var userHere = tab.getAttribute('widgetId').toString();             
 var underBar = userHere.lastIndexOf("_");                           
 var justTabName = userHere.substring(underBar + 1);                 
 var employer = document.getElementById('#id:computedField2}');      
 alert("employer:  " + employer);                                    
setCookie('justTabName',userHere.substring(underBar + 1),'1');       
        }                                                              
    }                                                                  
                                                                       
]]>                                                                    
</script>      
 
Where has my logic gone off the rails?
Apr 20, 2011, 7:26 PM
31 Posts
Re: Cannot Get Field Value From Inside Function
Have you tried using:
 
var employer = XSP.getElementById("#{id:computedField2}").value;
 
to get the value out of the variable?  I seem to have had to use something similar to the above to get at the value using CSJS.
 
 
Apr 20, 2011, 7:54 PM
10 Posts
Re: Cannot Get Field Value From Inside Function
Thanks for the thought Judy, but yep, I still get get XSP.getElementById....... is null.
 
I just saw this article about using dojo.query, but I can't seem to get that to work either http://rndnotes.wordpress.com/2011/03/03/105/
 
I did find that I can use var employer = document.getElementById("view:_id1:_id2:_id6:include1:employer_hidden_fields:computedField2").innerHTML; but I understand this is hard-coding a path that may change.  I'll have to do this if I can't get anything else to work, but there must be some way to get the system to dynamically provide the full path to the field.
 
 
 
 
Apr 20, 2011, 7:59 PM
31 Posts
Re: Cannot Get Field Value From Inside Function
To follow along your path, have you tried:
XSP.getElementById("#{id:computedField2}").innerHTML;  ?
Apr 20, 2011, 8:13 PM
10 Posts
Re: Cannot Get Field Value From Inside Function - GOT IT!!!
Yup, and I get the same results.  I have absolutely no idea why I couldn't use any of those configurations.
 
However, the good news is that with just a bit of tweaking, I was able to use the dojo.query to obtain the field value.  You use

var employer = dojo.query('[id$=\":EmployerID\"]')[0];
alert("employer:  " + employer.innerHTML);
 
I had used compositeData to bring the value of EmployerID from the custom control it was in, to the computedField2 on the current custom control.  However, with the above, I can directly access the data from the other custom control without using compositeData.  I had thought that was initially part of my problem - that the code couldn't 'see' the field because it was on another custom control and I understood that they can't see inside of each other.

Ya gotta love it when stuff works and in a more simple way than you were trying to do it!
 
Thanks so much for your help with this.  I do appreciate the suggestions.

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal