#Html.DropDownListFor(m => m.field, Model.fieldList, "Select")
I have the code above to get the values of a drop down list from a database. Because the database does not have the select value, I am add it to the list. However, I want to set the selected value to a certain value(variable). How can I do this?
Say I want the selected value to be "WI" and "WI" is in the list. How do i do this? Or how do I specify the #value property?
The DropDownListFor function will first look if there is a selected value in the provided select list. If there are no selected values in the selected list items, it will look at the value of the field that the drop down list is for and attempt to match that to the value of each select list item until it finds the correct one. If any select list item does not have value, it will compare it to the text instead.
Once you have the full list generated, loop through it and find the value you want selected, then set the selected property to true and it should choose that one.
Related
I am trying to set a interactive grid column value (which is a date) based on a page item (which is also a date). I have already tried defaulting and using dynamic action set value (jquery seletor) to set item value to the interactive grid column but it does not work how I want it to work.
I have a page item called "P_DEF_DATE" and I want to set a date column in the interactive grid to this value but I want when I change the value in the page item and I click add row on the interactive grid, it must always use whatever value I have in the page item. For example:
P_DEF_DATE = 12-JAN-2021
when I click on add row in the interactive grid, my date column must equal to P_DEF_DATE and i add a few rows based on that date but then i change the date of P_DEF_DATE to:
P_DEF_DATE = 28-JAN-2021
now I want when I click on add row in the interactive grid, I it must show this new date from the page item in the date column in the interactive grid, keeping in mind the page does not refresh and I have rows with the date 12-JAN-2021.
Thank you in advance!
I implemented same few days ago. Following is what I did.
Create Dynamic Action on Row Initialization Event, set Region to your IG
Set True Action to Execute JavaScript Code
Use code
var model = this.data.model,
rec = this.data.record,
meta = model.getRecordMetadata(this.data.recordId);
if ( meta.inserted ) {
model.setValue(rec,"COLUMN_NAME", $v("P_DEF_DATE"));
}
Replace JOB with your column name and P_DEF_DATE with you Item name
More details Here
Also, out of curiosity, why there is no number like P1, P2 in your item name ??
Using Robot Framework, I have a dropdown with multiple options. When I use the select from list option I can see the selection become highlighted, but when the dropdown closes, the value is not changed.
Here is a sample of my code:
click element id=month
select from list xpath=//select/#name="month" September
click button css=button.submit
I have tried variants of this with the select from list by label and select from list by value, and they fail with error stating the selected list or value does not exist.
Select from list by value example:
click element id=month
select from list by value xpath=//select/#name="month" September
click button css=button.submit
Select from list by label example 1:
click element id=month
select from list by label xpath=//select/#name="month" September
click button css=button.submit
Select from list by label example 2:
click element id=month
select from list by label xpath=//select/#name="month" label=September
click button css=button.submit
Anyone experienced this before where an item gets "selected" but the value does not get changed?
Use following keyword.
Pass locator as 1st argument and value as another argument
Select from list by label and validate
[Arguments] ${locator} ${select value}
Focus ${locator}
# Select from list by label
Select From List By Label ${locator} ${select value}
# Get selected value and validate it against passed value as argument
${value} = Get Selected List Label ${locator}
Should be equal ${select value} ${value}
I want to clear the toolbar of my grid, but not to the default value of the column. I want to empty all fields.
When I use the
$("#Jqgrid")[0].clearToolbar();
method the toolbar gets the initial default values..
You can choose one from the following two ways.
1) You can temporary change the defaultValue of the searchoptions to "" before call of clearToolbar. You can use setColProp method for example to change column properties (see en example here).
2) Set the value of the the toolbar element manually to "" or to any other value which you want. There are simple way how the ids of the input or select elements of the toolbar are constructed. Let us you have column with the name 'col1' (the corresponding column of colModel has name: 'col1'). Then the id of the element in the filter toolbar will be gs_col1. So you can use
$("#gs_col1").val("");
to clear the field. In more general case if the colname is the variable which hold the value from colModel[i].name you can use
$("#gs_" + $.jgrid.jqID(colname)).val("");
How do I add a Fetched Property in XCode's Data Model Editor for minimum value of one attribute??
My model:
Model http://www.freeimagehosting.net/uploads/b48853070e.png
Item (name, note, storedItem)
StoredItem (price, item)
Item 1 ---> N StoredITem (1->N Relationship)
I want that Item has a fetched property named minPrice and its value is the minimum value setted for price in the storedItems.
Example:
Item1 (banana, storedItem1 ... storedItem4, 10)
StoredItem1 (10,item1)
StoredItem2 (15,item1)
StoredItem3 (30,item1)
StoredItem4 (54,item1)
What do I put in Destination?? StoredItem?
Fetched Property in Data Model Editor http://www.freeimagehosting.net/uploads/2a68de007d.png
And what do I put in Expression??
Expression in Data Model Editor http://www.freeimagehosting.net/uploads/766ab9af6f.png
The destination is the type of entity you want back.
It sounds like you want a StoredItem back, since that has a price on it.
What I think you want is a fetched property on Item called minPrice, with this expression:
"#min.storedItems.price"
I'm trying to find a simple Selenium call to grab the current option from a select drop-down list. I'm aware there are calls which grab all the values in a list but I wish to know which option is currently selected. Apologies if this is trivial but google and Selenium IDE didn't help me. Thanks.
You should be able to use the getSelected* commands to return the ID, index, or label of the selected item. Below is quoted from the Selenium Reference:
storeSelectedId ( selectLocator, variableName )
Gets option element ID for selected option in the specified select element.
Arguments:
selectLocator - an element locator identifying a drop-down menu
variableName - the name of a variable in which the result is to be stored.
Returns: the selected option ID in the specified select drop-down
storeSelectedIndex ( selectLocator, variableName )
Gets option index (option number, starting at 0) for selected option in the specified select element.
Arguments:
selectLocator - an element locator identifying a drop-down menu
variableName - the name of a variable in which the result is to be stored.
Returns: the selected option index in the specified select drop-down
storeSelectedLabel ( selectLocator, variableName )
Gets option label (visible text) for selected option in the specified select element.
Arguments:
selectLocator - an element locator identifying a drop-down menu
variableName - the name of a variable in which the result is to be stored.
Returns: the selected option label in the specified select drop-down
I would use storeSelectedValue or getSelectedValue
JUNIT
String value = selenium.getSelectedValue(selectLocator)
Selenium Action
storeSelectedValue ( selectLocator, variableName )
there is a link to practice such things:
"https://letskodeit.teachable.com/p/practice"
there's a "Select Class Example"
1.in this test first it clicks on "Honda" in the dropdown menu
2. then extracts the select-tag as parent of the option-tag "Honda"
3. then converts it to Select object
4. then i uses the getFirstSelectedOption() to compare it with the expected value "Honda.
#Test
public void selectTagDemo() {
WebElement hondaElement = webDriver.findElement(By.xpath("//option[#value=\"honda\"]"));
hondaElement.click();
WebElement selectCarWebElement = hondaElement.findElement(By.xpath("//parent::select"));
Select selectCar = new Select(selectCarWebElement);
Assert.assertEquals(selectCar.getFirstSelectedOption().getText(), "Honda");
}
if you need the whole Test class comment below