I'm using Laravel 4. I'm having some problem. I have a users table with fields like. State, Region, Area and City, they are all in string (varchar).
Now, I have my "Edit Users" page. In edit users how can I display the users info ing State, Region etc. in a Select Dropdown? Here's my code.
{{ Form::select('state', array(
'' => 'Choose One', 1 => 'Luzon', 2 => 'Visayas', 3 => 'Mindanao'),
null,
array('class' => 'selectpicker',
'id' => 'state',
'data-live-search' => 'true',
'onchange' => 'document.getElementById("state2").value=this.options[this.selectedIndex].text'
));
}}
How can I make a value for that specific user already appeared or selected in the dropdown?
Thanks!
See if this works for you:
$states = array( 'Choose One', 'Luzon', 'Visayas', 'Mindanao' );
{{ Form::select('state',
$states,
array_search($user->State, $states ), // default value
array(
'class' => 'selectpicker',
'id' => 'state',
'data-live-search' => 'true',
'onchange' => 'document.getElementById("state2").value=this.options[this.selectedIndex].text'
));
}}
Related
I am using PBC (price based on country)Plugin to have different prices for different countries manually. As of now its showing "read more" at shop page if price is not set for particular product for a particular country while creating product.
i would like to hide all products if product with text "read more" or with no price are created for particular country & when woocommerce country is selected from drop down widget at homepage by the customer if product is not available in his selected country.
I have tried following solution with different combinations:
add_action( 'woocommerce_product_query', 'react2wp_hide_products_without_price' );
function react2wp_hide_products_without_price( $q ){
$meta_query = $q->get( 'meta_query' );
$meta_query[] = array(
'key' => '_Brazil_regular_price' ,
'value' => '',
'compare' => '!='
);
$meta_query[] = array(
'key' => '_Cannada_price' ,
'value' => '',
'compare' => '!='
);
$meta_query[] = array(
'key' => '_price' ,
'value' => '',
'compare' => '!='
);
$q->set( 'meta_query', $meta_query );
}
Above query doesn't seems to be working properly.
I'm developing a prestashop module.in my controller renderForm i have drop down list to load week days.but it showing only first letter of the day.
public function renderForm() {
$days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
'input' => [
[
'type' => 'select',
'lang' => true,
'required' => true,
'label' => $this->l('WeekDay'),
'name' => 'weekday',
'options' => [
'query' => $days,
],
],
]
}
Showing like this
Inspect Element
Your query value should be like below format as per prestashop 1.7 documentation.
$days = array(
array(
'id' => 1, // The value of the 'value' attribute of the <option> tag.
'name' => $this->trans('Monday', array(), 'Admin.International.Feature') // The value of the text content of the <option> tag.
),
array(
'id' => 2,
'name' => $this->trans('Tuesday', array(), 'Admin.International.Feature')
),
);
I use the yii2 kartik switch input with the type radio and i want to get the value of the selected option in javascript (specially in a JsExpression), here is my code :
$model->orientation = 'Portrait';
echo $form->field($model, 'orientation')->widget(SwitchInput::classname(), [
'name' => 'information_orientation',
'type' => SwitchInput::RADIO,
'value' => 'Portrait',
'items' => [
['label' => 'Portrait   ', 'value' => 'Portrait'],
['label' => 'Paysage   ', 'value' => 'Paysage'],
],
'pluginOptions' => [
'onText' => 'Oui',
'offText' => 'Non',
'onColor' => 'success',
'offColor' => 'danger',
'size' => 'mini'
],
'labelOptions' => ['style' => 'font-size: 13px'],
]);
I have tried :
$([name='information-orientation']).val()
But it returned an undifined value
SwitchInput class does not care about the name property you give it
according to their docs, you need to wrap name in a options array
echo $form->field($model, 'orientation')
->widget(SwitchInput::classname(), [
'options' => ['name' => 'information_orientation'],
'type' => SwitchInput::RADIO,
....
from docs:
options: array the HTML attributes for the widget input tag.
edit:
you can then use the following
// to get value:
$("[name='information_orientation']").val()
// to check if the switch is or on off
$("[name='information_orientation']").prop('checked')
I want to set the hidden input field value to selected drop box value. Here is my hidden field code and drop box code.
{!! Form::hidden('color') !!}
{!! Form::select('type', array('type' => 'type','Orange' => 'Orange', 'Red' => 'Red','Green' => 'Green'), 'type') !!}
Below is my jquery.
<script>
$(document).ready(function(){
$('#type').on('change',function(){
$('#color').val($(this).val());
});
});
But as the hidden field value it will not set the value. Why is that?
aYou are referencing an element whose ID is "type", but you don't have any.
Add the type ID to your select box.
Try this:
{!! Form::hidden('type', null, array('id' => 'color')); !!}
{!! Form::select('type', array(
'type' => 'type',
'Orange' => 'Orange',
'Red' => 'Red',
'Green' => 'Green'
), 'type', array(
'id' => 'type'
)) !!}
Laravel 5 FormBuilder API Documentation
Further reading
Hi guys i have a gridview like below
and i want to get the 'user_id' of the checked column
how can i do that???
I could easily get the checked column id but i dont know how to get data of those checked column in gridview
i want to get it via javascript so that i can pass it to service
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showOnEmpty'=>true,
'columns' => [
['class' => 'yii\grid\CheckboxColumn'],
[
'attribute' => 'event_id',
'label' => 'Event Title',
'value' => 'event.title'
],
[
'attribute' => 'user_id',
'label' => 'Email',
'value' => 'users.email',
],
'user_type',
],
]);
?>
and here is my javascript to get ids of checked column
jQuery(document).ready(function() {
btnCheck = $("#send");
btnCheck.click(function() {
var keys = $("#w0").yiiGridView("getSelectedRows");
}
});
Let me tell you the flow of this
On homepage is a gridview like this
Now user will click on that small user sign and that will open the page you can see below
Thats when i want to send messages to all selected users
Because in my case title is from different table and name and email are from different table so i want ids of user table
For that i want user_id but i am getting some random values
What can i do here???
I tried this but its returning some random string
public function search($params)
{
if(!isset($_GET['id'])){
$id='';
}
else{
$id=$_GET['id'];
}
$query = Checkin::find()->where(['event_id'=> $id]);
$query->joinWith(['event', 'users']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'created_date' => $this->created_date,
'created_by' => $this->created_by,
'updated_date' => $this->updated_date,
'updated_by' => $this->updated_by,
]);
$query->andFilterWhere(['like', 'user.email', $this->user_id]);
$query->andFilterWhere(['like', 'user_type', $this->user_type]);
$dataProvider->keys ='user_id';
return $dataProvider;
}
Update your DataProvider set $dataProvider->keys ='userId' then you will able to get all keys of user_id
data-id of GridView and get allSelectedColumns
You need to just replace this code
['class' => 'yii\grid\CheckboxColumn'],
with below code
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($data) {
return ['value' => $data->user_id];
},
],