default value bind to select box - angularjs

I have got simple select box which should be set as default to state Active(true) or Blocked (false).
Any ideas how to do it as simple as it is possible ?
<select class="form-control" ng-model="selectedUser.active" >
<option value="true">Active</option>
<option value="false">Blocked</option>
</select>

Solved by adding
<option ng-selected="selectedUser.active" value="true">Active</option>
<option ng-selected="!selectedUser.active" value="false">Blocked</option>

Related

React to select default value of a drop-down

In my code, I want to make it a default selected value if there is only one.
As of now the code looks as follows:
<select
name="something"
value={this.props.parentProps.value}
<option value="" disabled selected>--Select--</option>
<option value="Other">Other</option>
</select>
The idea here is to have the only option selected, if there is only one.
I could copy them out to and array within the code if needed:
<select options={something}
What would you recommend?
Basically I want something like:
if(only one option)
Select(that one);
you can do something like this:
<select
name="something"
value={this.props.parentProps.value}
<option value="" disabled selected={options.length === 1}>--Select--</option>
<option value="Other">Other</option>
</select>
this options.length === 1 will return true or false that will trigger the selected

ReactJS Reactstrap input dropdown not showing selected value

I am using reactstrap with React JS and trying to figure out how to bind the input dropdown list.
When the data is coming in, the optionID can be from any from 1 to 5. I would expect that
when I bring up the UI, the dropdown is always showing Select option and never the other.
I thought if I set the selected={this.state.optionID === Input.value} it would make it work.
Any help is appreciated. Thanks.
<Input type="select" name="select" id="statusDropDown"
value={this.state.optionID} selected={this.state.optionID === Input.value}
onChange={this.handleOptionChange}>
<option value={0}>Select</option>
<option value={1}>Option 1</option>
<option value={2}>Option 2</option>
<option value={3}>Option 3</option>
<option value={4}>Option 4</option>
<option value={5}>Option 5</option>
</Input>
Please find the working sample here. My suggestion is to use a functional component.

Setting existing value as default in Select dropdown

I have a drop down which contains the following values
<select class="form-control">
<option value="critical">Critical</option>
<option value="high">High</option>
<option value="medium">Medium</option>
<option value="low">Low</option>
</select>
Because of this in drop-down the value is always selected to "Critical"
In my scope i have defined the values of severity per drop-down. How do i select that ?
For example say the value is "High". How do i set the default value to high and not critical
You'll need to define at object within your scope and bind it to the ng-model of your select.
Script
$scope.form = {
"severity": "high"
};
HTML
<select class="form-control" ng-model="form.severity">
<option value="critical">Critical</option>
<option value="high">High</option>
<option value="medium">Medium</option>
<option value="low">Low</option>
</select>
There are a couple of ways to select an option with angular:
1- Bind it to a model and set the model:
<select class="form-control" ng-model="myValue">
And
$scope.myValue = 'medium';
2- You can set it in a directive by jQuery or JS:
$("#yourselectid").val('low');

Option value is not getting selected

I am trying to select one of the option , my code is pass but at UI no option get selected .
Here is HTML code:
<select name="ddlMarketSource" id="ddlMarketSource" class="select fontb selectchange" originalvalue="0" style="width:100px;">
<option selected="selected" value="0">Select</option>
<option value="1">Call In</option>
<option value="2">Fax</option>
<option value="3">Email</option>
<option value="4">SMS</option>
<option value="5">News(Includes EPRC, Cybernet, Newspaper)</option>
<option value="6">Cold Call</option>
<option value="7">Search</option>
<option value="8">Mortgage</option>
<option value="9">Referral</option>
<option value="10">N/A</option>
</select>
Here is my statement to select :
Select mrkSource = new Select(driver.findElement(By.xpath("//*[#id='ddlMarketSource']")));
mrkSource.selectByValue("1");
Your code works on my machine.
I have selenium 2.52.0 and Firefox 44.
Try to verify if you are selecting right element. In Chrome you can open console and write
$x("//*[#id='ddlMarketSource']")
to check your xpath.

Default selected value not working using ng-init

Simply trying to make a default selected value in Angular but thus far I am having no luck.
HTML Before Compile:
<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" ng-init="rule.MatchLogic = 0" ></select>
HTML In Browser Source:
<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" class="ng-pristine ng-valid">
<option value="?" selected="selected"></option>
<option value="0">All</option>
<option value="1">At Least</option>
<option value="2">At Most</option>
</select>
How do I make value=0 (All) the default selected value.
All you need to do is set your ng-model value rule.MatchLogic to equal the corresponding value in the options. The options you use are ruleSelect.
So for example, set rule.MatchLogic = ruleSelect[someSelector].Value; inside your controller.

Resources