Here i like to set preselected value in yii2 dropdownlist,
this is my dropdownlist, how i can set preselect value in this
<?= $form->field($model, 'tpa_email')->dropDownList(
ArrayHelper::map(Approvaldetails::find()->all(),'id','tpa_email'),
['prompt' => 'Select Tpa Email..'])
?>
becoz everytime while updating the form , value getting reset.
The value of $model->tpa_email will be used to select the value from the list items. So make sure that $model->tpa_email contains the key of the value you want to have selected.
As jagsler said you just have to set the key of the dropdown value to model. Try following in your controller:
$model->tpa_email = $key;
Where $key will be the key of the preselected option you want to set.
Related
How can I change the value of the attribute in a grid on runtime?
For example, I have an IsActive attribute with a boolean datatype in a Transaction and I put it on a Grid in web panel. I want it to display as Text like 'Active' if the value is true and 'Inactive' otherwise.
Here's the screenshot: link
Attributes in WebPanels grids are readonly
You can add a variable in the grid... char(20),
in load code, set something like this:
iif(StaffIsActive, 'Active', 'Inactive')
You are using WW+, here is a help for this:
Grid Variable
I have an el-select of which uses v-for to populate data from an array; i want to set the default value on load a value within the array, but still have the option of selecting another value if i want...
CODE
<el-select class="select-large" #change="getRate(recipient_type_id)" v-model="recipient_type_id"
placeholder="Select">
<el-option
v-for="(item) in recipientDetails"
:key="item.id"
:label="item.display_name"
:value="item.type_details">
</el-option>
</el-select>
the array is recipientDetails and i have a default recipient whom should be loaded first instead of the placeholder...
thanks in advance
You can selected option via set a value for :selected attrs of `
<el-option
v-for="(item) in recipientDetails"
:selected="other_detail"
:key="item.id"
:label="item.display_name"
:value="item.type_details">
</el-option>
if other_detail equals :value value, so the option selected.
When using v-model on select, you can't use the selected attribute on an option.
Since you've bound the select to recipient_type_id, Once your data loads, I'll advice you to run through the items in recipientDetails, find the item with a type_details property that should be the default and assign that value to recipient_type_id like so
this.recipientDetails.forEach(detail => {
if(detail.tpye_details == default_value){
this.recipient_type_id = detail.type_details
}
}
The simplest way I found is to have the default value assigned to recipient_type_id is the data() then it will filter automatically.
I am using Laravel 4.2 and i fetch all locations with this code:
$locations = Location::all();
This Locations are displayed in a select box afterwards. How can i add an additional row to the results in order to show an empty first option in the select box.
The options then should be:
choose a location
location 1
location 2
...
I just want to add an additional item to the result in $locations.
Thanks in advance
You can use:
{!! Form::select('location', ['' => 'Select your location'] + $locations, null , ['class' => 'form-control']) !!}
to update the view. In Laravel 5 there are attribute accessors to append an extra field with your eloquent collection.
Few other ways to do this are:
$locations[null] = 'choose a location';
Form::select('location', $locations);
Form::select('location',[null=>'Please Select'] + $locations);
Another way is to loop through the result and update it. Use json_decode() or 'toArray()` to convert your result into array format.
Otherwise you have to store choose a location as the first row value in your locations table(I know that is inappropriate for the requirement).
You should look at the put method for collections:
https://laravel.com/docs/5.6/collections#method-put
This method is not available in 4.2. You should make a custom Collection class and use it in your model by overwriting the newCollection method. https://laravel.com/docs/4.2/eloquent#collections
I am using dropdownlist in activeform, but i am facing the below issue.
I get the data as an array from the database, but when I display it, even the key value is being displayed. How do I prevent that from happening?
I am getting output as below
0
First
1
Second
I want the dropdownlist to display just the data and not the key values.
First
Second
Below is my code:
$query1 = (new Query())->select('model_name')->from('cars');
$data=$query1->all();
<?= $form->field($model, 'dealer')->dropDownlist($data) ?>
In your code $data is an array of rows and not strings. Try this:
$data = (new Query())->select('model_name')->from('cars')->column();
Doc: Query::column()
how to set drop down as invisible when page loading in codeigniter.i want to show that drop down later. This is my code for drop down load from database results..how do i set visibility :none or invisisible this drop down
foreach ($sources as $row) {
$options3[$row->id] = $row->source;
}
echo '<td>'.form_dropdown('source_id', $options3, $this->input->post('source_id'), "id='source_id'");
Just add any attribute you need as a string in the fourth parameter of form_dropdown()
form_dropdown('source_id', $options3, $this->input->post('source_id'), "id='source_id'");
becomes
form_dropdown('source_id', $options3, $this->input->post('source_id'), "id='source_id' style='display:none;'");
echo
''.form_dropdown
('source_id',
$options3, $this->input-
post('source_id'),
"id='source_id' style='display:none;' "); #pass the style in the fourth parameter to hide the combo