How do get id & text from a dojo/dijit combobox? - combobox

How do you get the id for the underlying record in a combobox with dojo? I've tried altering the following sample but all I can get is the text shown to the user (the "name" property of each array element), and NOT the state's two-letter abbreviation ("id" property).
http://dojotoolkit.org/reference-guide/1.10/dijit/form/ComboBox.html#id3
thanks. PS, I'm a total noob with dojo. This is my first experiment with it.

It's like #CodeCrisis said, you can get the item by using dijit.byId('stateSelect').item. Though I'm not really pleased with how outdated the docs are (the dijit.byId()command is deprecated), this is a proper 1.10 solution:
query("button").on('click', function() {
console.log(comboBox.get('item'));
});
This will return the selected record in the store (containing both the id and name properties in this case).
A full, working example can be found here: http://jsfiddle.net/zt6xggL8/

How about this...
base on the link given
http://dojotoolkit.org/reference-guide/1.10/dijit/form/ComboBox.html#id3
change this onclick function
onClick="alert(dijit.byId('stateSelect').get('value'))"
into
onClick="alert(dijit.byId('stateSelect').item.id)"
i know this is not the best answer but i hope this will help you..
check out the answer of Philippe
Dojo : ComboBox selected and show data id
hehehe... :)
just passing by...

Not the prettiest but this works. Basically need to query the 'store' variable for the name that is being displayed when you just use 'value'. [0] denotes the first object in the store list, so if you have multiples with the same name, you'll need to use the foreach() function.
<button onClick="var namevar=dijit.byId('stateSelect').get('value');
alert(dijit.byId('stateSelect').get('store').query({name:namevar})[0].id);">
Get value
</button>

Related

xpath for specific code in WebDriverSampler

I have a page with a set of fields I need to edit via WebSamplerDriver.
The difficulty is that field id values are not constant and change from time to time.
So, if I use an xpath like //input[#id='TextField13'],
it works only very limited time while id is actual.
Code snippet is below:
I suppose I need to describe xpath for an element with id='TextField13' (which is not a constant) with relevance to the text "First name" (always the same text) in another branch of parent tag (i.e. label).
What is the right way to do that?
Will be appreciated for tips.
Try this XPath to select input field based on label value
//label[.="First name"]/following::input
The answer is:
//label[contains(text(),'First name')]//following:://input

Change a parameter type of a Lodash function

I'm newbie to Lodash and I use it within TypeScript coding. So I have an array of objects called items (of foods), every item has a category object parameter (with id & name attributes), so it looks like this :
I want to group those items by categroy names, I've created a new Object of type any called foodLists (public foodLists: any;),
and after loading those items, I've tried this:
this.foodLists = lodash.keyBy(this.items, 'category.name');
Actually, it did a part of the work, so it appears like this:
So the items are sorted by category , the issue is that it afftected just an only item to each category , however I want that many items should be affected to each category
So the second parameter of lodash.keyBy() (which is here 'category.name') should accept an array of objects. Hope you understand me. Is that possible ? or is there any alternative in lodash that gives the wanted result ? and Thank you.
it seems the solution is _.groupBy
lodash.groupBy(this.items, 'category.name')

Not able to locate an element, element id is not unique every time

I'm trying to locate an element using xpath, but not able to make it unique as some part of element is come new every time. I have below element ID :
id= dnn_ctr173273_ProgramWizardBase_ctl00_AddNewLink
but for every portal the number get changes e.g. 173273 to 65662
and id becomes dnn_ctr65662_ProgramWizardBase_ctl00_AddNewLink
Please suggest me how do i make it unique.
Go through this,
css=a[id^='id_prefix_']
css=a[id$='_id_suffix']
css=a[id*='id_pattern']
Hope, it will definitely help you :)
You can find the element by partial id
driver.findElement(By.cssSelector("id*='ProgramWizardBase_ctl00_AddNewLink'"));
This will search for id witch contains the text ProgramWizardBase_ctl00_AddNewLink.

Xpages Combobox -setting the default value

I have a combobox with values being populated from a managed bean like so:
keywordlist.setConnDB("jdbc:sqlserver://xx.xx.x.xx:1433;DatabaseName=xxx");
keywordlist.setConnUserName("xxx");
keywordlist.setConnPassword("xxx");
keywordlist.setSQLQuery("SELECT DisplayText as Keyword From Glossary WHERE SUBSTRING(DisplayText, 1, 2)= 'RV'");
keywordlist.keywords;
I'd like to be able to set the default to '--- Select ---', but no matter what I do the keyword list always picks the first of the returned keywords as the default.
Any assistance would be much appreciated.
Thanks,
Dan
Add another value pair (on first position), type "formula item" with the following SSJS return value:
"-- Select --|"
Notice the pipe!
That should display this at first position and should also be defaulted as "empty" is the default value. If not, set the "alias" (the value after the pipe) to something that you can define as default value porperty for the combo item.
It might be because you're binding to the bean directly. You might have to add that value to your keyword list itself. I think I have an example of this in a NotesIn9 show: http://notesin9.com/index.php/2014/03/13/notesin9-138-xpages-combobox-improvements/
I'm not sure. If I don't have a default in the java code you can probably see how it might be done.
Try that. If that doesn't work at all then maybe you don't bind the combo box to the bean directly. Maybe bind it to a viewScope var... since that can be anything it'll take a blank... then you just need to move the viewScope var value back up to your bean in the onChange event or something.
Just a quick thought...
Basically, the following pattern could be a start point for such a combobox:
<xp:comboBox
id="comboBox1"
defaultValue=""
value="#{document1.someField}">
<xp:selectItem
itemLabel="--- Select ---"
itemValue=""></xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:
// Your SSJS code...
// Should return some kind of list...
return items;
}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Alternatively, you can grab the keyword values from a Java bean:
<xp:selectItems value=#{yourBean.yourValue}></xp:selectItems>
Still, it's important to return a list value. It might also have "label|value" format.

How to declare, same webelement with different ids using Findby?

For instance, is it possible to define:
#FindBy(By.id("id1") OR By.id("form1:id1"))
public WebElement button
So that button having either "id1" or "form1:id1" should work fine?
You can use the #FindBys annotation, the syntax is:
#FindBys({#FindBy(id = "foo"),
#FindBy(className = "bar")})
The JavaDoc describes it here:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/FindBys.html
Well,
use whathever you want, as long as it works
Personally I would use #FindBy(By.id("id1")) but it is just point of choice.
Also, there is no value added in referring same element twice with two different methods. It will only cause mess in your code
EDIT
As I understood your comment, there is element on the page which constantly changes its ID. If you need to refer to such elements, try using xPath See for example this xpath tutorial
The idea is that you will point to some place in the DOM rather than to specific ID
Use Xpath or CSS selector to do that. Or Java to store the ID name in String and then you can fill it to your Id.

Resources