I know that client javascript can get the hierarchical id of an element with (for example) ‘#{id:someId}’.Is there a similar way to get an element’s name?
I tried using ‘#{name:someName}’ but that doesn’t work. It produces an error like:
name:someName
Encountered “: someName }”, expected one of [“}”, “.”, “>”, “gt”, “<”, “lt”, “==”, “eq”, “<=”, “le”, “>=”, “ge”, “!=”, “ne”, “[”, “+”, “-”, “*”, “/”, “div”, “%”, “mod”, “and”, “&&”, “or”, “||”, “:”, , “(”, “?”]
Encountered “: someName }” at line 1, column 7. Was expecting one of: “}” … “.” … “>” … “gt” … “<” … “lt” … “==” … “eq” … “<=” … “le” … “>=” … “ge” … “!=” … “ne” … “[” … “+” … “-” … “*” … “/” … “div” … “%” … “mod” … “and” … “&&” … “or” … “||” … “:” “(” … “?” …
Subject: Re: XPages - how to get full name of an element in client javascript?
getClientID is what you want. Use getClientID(“somename”) to get the full path and pass into your server-side script. See this post from John Mackey.
http://mattwhite.me/11tmr.nsf/D6Plinks/MWHE-7K9BC3
Alternatively, you can get the releative path for all controls (computed fields, edit boxes etc) on a given custom control by adding a computed field control to your custom control called elementPath with this code:
return @LeftBack(getClientId(“elementPath”), “elementPath”)
This will return the relative path to the current custom control, so you can add this to any id in your server-side javascript to get the value.
Regards
Paul
Subject: No, that doesn’t help. I need the actual HTML “name” attribute…
Looking at the rendered HTML, the getClientId function only works with the “id” attribute, as does a construct like “#{id:someId}”.I need the “name” attribute, so I want something like “#{name:someName)” or a “getClientName” function, but apparently neither exist.
The reason for this is that, if I have a bunch of radio buttons in one group, I want to use document.getElementsByName in client javascript to get all the radio buttons in one array.
Here’s a real example. Part of the XML in an XPage looks like this:
The resulting HTML looks like this:
Note that the XPage “groupName” attribute has become the HTML “name” attribute, but with a hierarchy added. Assuming that the client-side HTML name is not reliably predictably, I need to be able to get that when I only know the XPage groupName, which I set to “barcodeOpt” in this case.
For now, I have written a function which gets one of the radio buttons by its id, then gets the name of that element and assumes the other has the same name. It should be easier than this.
As an aside: it’s confusing that the XPage design UI shows a property labelled “name” for each element, but that does not connect to the HTML name attribute. It connects to the id attribute instead.
Subject: getClientId with @LeftBack
In which case, add a computed field called elementPath with this formula
return @LeftBack(getClientId(“elementPath”), “elementPath”)
The element’s id will be, for your example, “view:_id1:elementPath”, so the field will return “view:_id1:”. You know the groupName value, “barcodeOpt”, so you can pass the elementPath value across into your function. Your code can then use that value + “barcodeOpt” as the parameter for document.getElementByName().
Should work fine.
Paul
Subject: That’ll do. Thanks.