I'm trying to do this:
echo $this->Form->input("filter.wijk", array(
'onChange' => 'this.form.submit()',
'type' => 'select',
'multiple' => 'checkbox',
'options' => $wijkOpties,
'label' => false)
);
However, the onChange attribute does not appear in the resulting HTML. The documentation for FormHelper::input tells us this:
* ### Options
*
* See each field type method for more information. Any options that are part of
* $attributes or $options for the different **type** methods can be included in `$options` for input().i
* Additionally, any unknown keys that are not in the list below, or part of the selected type's options
* will be treated as a regular html attribute for the generated input.
Am I interpreting that last sentence in the wrong way?
You have 2 options:
1- Give up on the checkboxes and simply get a normal select list element/box:
echo $this->Form->input("filter.wijk", array(
'onChange' => 'this.form.submit()',
'type' => 'select',
'multiple' => true,
'options' => $wijkOpties,
'label' => false)
);
2- Do a workaround for a valid checkboxes list (Something like):
$i = 0;
foreach($wijkOpties as $value => $option){
echo $this->Form->input('filter.wijk.' . $i++, array(
'onChange' => 'this.form.submit()',
'label' => $option,
'value' => $value,
'type' => 'checkbox',
));
}
`
Related
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'm designing a website for a local performing arts venue, and I would like to add some code so that specific event posts on the "Events" page will automatically be moved from "Events" to a different "Past Performances" page after the date of the event has passed. I've looked around for any existing solution to this query and haven't yet found one.
Create a child theme or add page-events.php and page-past-performances.php, you may copy/paste your current theme page.php code.
Here you may choose 2 options:
Create a special loop for each template. For page-events.php:
<?php
$today = getdate();
$args = array('date_query' => array(
array(
'after' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
'inclusive' => true
)
));
$query = WP_Query($args);
//Here goes the loop
For page-past-performances.php:
<?php
$today = getdate();
$args = array('date_query' => array(
array(
'before' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
inclusive => false
)
));
$query = WP_Query($args);
//Here goes the loop
The second option uses the action hook pre_get_posts, it could look something like this (inside your functions.php file):
<?php
add_action('pre_get_posts', 'date_filter');
function date_filter($query) {
if($query->pagename == 'events') {
$query->set('date_query', [[
'after' => //same as above
'inclusive' => true
]]);
}
if($query->pagename == 'past-performances') {
$query->set('date_query', [[
'before' => //same as above
'inclusive' => false
]]);
}
}
?>
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 am trying to get the IDs of all the selected check boxes in yii using JAVASCRIPT. Now i am able to get only the first element ID. Can anyone please suggest the correct code to get all the check box ID.
My View:
<input type="button" value="Multiple Host Date Entries" onclick="act();" />
<div id="grid"></div>
<?php
//zii.widgets.grid.CGridView bootstrap.widgets.TbExtendedGridView
$obj=$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'host_grid',
'dataProvider'=>$dataProvider,
'type' => 'striped bordered',
//'filter' => $model,
//'type' => 'striped bordered condensed',
//'summaryText' => false,
////'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array(
'id' => 'selectedIds',
'class' => 'CCheckBoxColumn',
'selectableRows'=>2,
'value' => '$data->host_id',
'checkBoxHtmlOptions' => array('name' => 'idList[]'),
),
array( // display 'create_time' using an expression
'name'=>'host_name',
'value'=>'$data->host_name',
),
array(
'name'=>'host_serviceid',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'status',
'value'=>'$data->status',
),
array(
'class'=>'CButtonColumn',
'template'=>'{edit_date}{update}{delete}',
'htmlOptions'=>array('width'=>'95px'),
'buttons' => array(
'update'=> array(
'label' => 'Update',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/a.png',
),
'delete'=> array(
'label' => 'Delete',
'imageUrl' => Yii::app()->baseUrl.'/images/icons/d.png',
),
'edit_date' => array( //the name {reply} must be same
'label' => 'Add Date', // text label of the button
'url' => 'Yii::app()->createAbsoluteUrl("NimsoftHostsDetails/View", array("id"=>$data->host_id))', //Your URL According to your wish
'imageUrl' => Yii::app()->baseUrl.'/images/icons/m.png', // image URL of the button. If not set or false, a text link is used, The image must be 16X16 pixels
),
),)
),
))
;
?>
I must select some check boxes and click on multiple host date entries button to go to the specific controller.
My JavaScript:
function act()
{
var idList=$("input[type=checkbox]:checked").serializeArray();
var jsonStr = JSON.stringify(idList);
/* Object.keys(idList).forEach(function(key) {
console.log(key, idList[key]);
alert(idList[key]);
});*/
var a=$("input[type=checkbox]:checked").val();
alert(a);
if(idList!="")
{
if(confirm("Add Dates for multiple hosts?"))
{
var url='<?php echo $this->createUrl('Nimsoft/Date_all',array('idList'=>'val_idList')); ?>';
url=url.replace('val_idList',jsonStr);
//url=url.replace('val_idList',json_encode(idList));
//alert(url);
window.open(url);
/*$.post('Date_all',idList,function(response)
{
$.fn.yiiGridView.update("host_grid");
});*/
}
}
else
{
alert("Please Select atleast one host");
}
}
I need to pass the IDs to NIMSOFT controller so that I can have a for loop to process each one of those.
you can retrieve the checked column in client side (javasctipt):
var idArray = $(gridID).yiiGridView('getChecked', columnID);
// or
$.fn.yiiGridView.getSelection(gridID);
For all checked row ids we use this
var id = $.fn.yiiGridView.getChecked("your-grid-id", "selectedIds"); // array of seleted id's from grid
I have a form with select input. I want to auto submit the form when the dropdown list was selected.
My code:
<?php echo $this->Form->create('Product', array('controller'=>'products', 'action'=>'shipping_area'));
echo $this->Form->input('area', array('options' => array('1' => 'Within Malaysia', '2' => 'International'), 'empty' => 'choose area',
'label' => 'Choose shipping area', 'onChange'=>'javascript:this.form.submit()'));
//echo $this->Form->end('Save');
?>
I put 'onChange'=>'javascript:this.form.submit()', but it goes to http://localhost/cake/cake/products/shipping_area ( supposely http://localhost/cake/products/shipping_area )
I also tried 'onChange'=>'this.form.submit()', but got same error.
can anyone please help.
You can add an "id" attribute to the form and then every time that you get an "onchange" event in the "select" element, you have to obtain the "id" value and pass it to the javascript function "document.getElement('idValueHere')" and call to the fuction submit. More clearly, the following code:
<?php
# step 1: add an id attribute ('id' => 'anyFormName') to the array options
# step 2: add an onchange envent to the dropdown ('onChange'=>'document.getElementById("anyFormName").submit();')
echo $this->Form->create('Product', array('controller'=>'products', 'action'=>'shipping_area', 'id' => 'anyFormName'));
echo $this->Form->input('area', array('options' => array('1' => 'Within Malaysia', '2' => 'International'), 'empty' => 'choose area',
'label' => 'Choose shipping area', 'onChange'=>'document.getElementById("anyFormName").submit();'));
//echo $this->Form->end('Save');?>
Hope it helps you.
echo $this->Form->create('Product', array(
'url' => array(
'controller'=>'products', 'action'=>'shipping_area'
)
));