I'm trying to do 3 selects in cakePhp + jQuery first one with provinces, second - localities, third - schools in that place. Here is my cake code (so far):
echo $this->Form->input('proviences', array(
'type' => 'select',
'empty' => true,
'options' => $proviences,
'label' => 'Province',
'class' => 'proviences',
'before' => '<div style="float:left;width:180px"',
'after' => "</div>"
));
echo $this->Form->input('localities', array(
'type' => 'select',
'empty' => true,
'options' => $localities,
'label' => 'City',
'class' => 'localities',
'before' => '<div style="float:left;width:180px"',
'after' => "</div>"
));
$schoolList = array();
foreach($schools as $value) {
$schoolsList[]=$value['name'];
}
echo $this->Form->input('school_id', array(
'label' => 'Szkoła',
'options' => $schoolsList,
'empty' => true,
'before' => '<div style="float:left;width:240px"',
'after' => "</div>",
'onchange' => "submit();",
));
In $schools i have a list looking this way
array(
id1 => array(
'name' => 'some_name',
'province' => 'some_province',
'locality' => 'some_city'
)
)
and using this to get lists of provinces,localities and school names
I was trying to use this but couldn't get it working ;/
Filter three select boxes based on previous selections
Is there a way of doing it in jQuery without ajax?
you can do it without using ajax, but for that you would need the schools array on client side, and create/edit options based on that on the client side, too.
here is a working fiddle. (hastily thrown together, but you get the idea). You need to get the schools array into js, though. you could either use AJAX for that or, pass it as json on the page:
echo 'var schools = JSON.parse('.json_encode($schools).');
You have to think about where to place that, too, so that the variable doesn't leak into the global scope. you could put it in the jQuery closure, for example:
echo '(function($){';
echo 'var schools = JSON.parse('.json_encode($schools).');
// now the javascript from the fiddle...
echo '}(jQuery))';
Related
I want to add 21 checkboxes and a text field(Name) in a good design way. Also there must be "check all button" to check all the checkboxes, how to do it in module PHP page in prestashop.
Since I am new to prestashop I don't know about the form submission, I have to save these two fields together as a json array in database.
Is that possible in prestashop? please help me regarding this.
prestashop version = 1.6
Thanks in advance
Sample code
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l( 'Generate Export Order Settings' ),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'checkbox',
'name' => 'display',
'values' => array(
'query' => array(
array(
'id' => 'all_fields',
'name' => $this->l('All Fields'),
'val' => '1'
),
),
'id' => 'id',
'name' => 'name'
)
),
),
'submit' => array(
'title' => $this->l( 'Save Export Settings' ),
'class' => 'button pull-right',
'name' => 'save-main-display-settings',
)
),
);
}
I don't know how to add check box in 3 columns and 7 rows and select all button to select all the checkbox.
You can use the following JS code to add check all functionality:
$('.chk_boxes').click(function(){
var chk = $(this).attr('checked')?true:false;
$('.chk_boxes1').attr('checked',chk);
});
Fiddle here: http://jsfiddle.net/HBGzy/
I have data in Drop down list as per role(for every role table are different).
I don't have any idea how to do because I am not familiar with yii2 First select a role and after selecting role I want data from different different table as per role
<?= $form->field($model, 'role')->dropDownList( [ 'A' => 'Admin', 'M' => 'Member', 'P' => 'Practice', ],['prompt'=>'--Select a Role--',]);?>
<?= $form->field($model, 'code')->dropDownList(
ArrayHelper::map(Member::find()->all(), 'id', 'memberCode'),
['id'=>'memberCode']
);
?>
You Need to update your 2nd dropdown when you select any value from dropdown 1st. Lets say 2nd drop down have id #dropdown2 so, i dit in yii you can change it according to yii2.
echo $form->dropDownListGroup(
$model, 'id', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' => CSystemGenerated::getProjectName($model->c_id),
'htmlOptions' => array(
'prompt' => 'Select Project',
'ajax' => array(
'type' => 'POST',
'url' => your url,
'update' => '#dropdown2',
//'dataType' => 'json',
'data'=>array('id'=>'js:this.value'),
)
),
),
)
);
<?php
echo $form->dropDownListGroup(
$model, 'tag', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' =>$this->getTags(),
'htmlOptions' => array(
'prompt' => 'Select Tags',
),
)
)
);
?>
check this link it will help you more.
Link1
link2
Please Refer to Kartik Dependent Drop Down in Yii2 ..This will surely helpfull
Ok, So I am trying to implement sort of a livesearch using the cake's Js Helper. The user will select a criteria to search by, using a drop down, and then tyoe in his search in an input text field. So far, this is what I have.
echo $this->Form->create(false,array('type'=>'post','default'=>false));
echo $this->Form->input('criteria',array(
'label'=>'Search Criteria',
'options' => array(
'id'=> 'By ID',
'name' => 'By Name',
'blood' => 'By Blood Type',
'type' => 'By Donor Type',
'age' => 'By Age',
'gender' => 'By Gender'
)
));
?>
Here is the input:
<?php echo $this->Form->input('query', array('type' => 'text', 'id' => 'query', 'name' => 'query', 'label' => false, 'placeholder' => 'Search')); ?>
<div id="loading" style="display: none; ">
<?php echo $this->Html->image('ajax_clock.gif');?>
</div>
And this is my Js code generated using the helper!
<script type="text/javascript">
<?php
echo $this->Js->get('#query')->event('keyup',$this->Js->request(
array('controller' => 'donors', 'action' => 'search'),
array('update'=>'#results','async' => true,'dataExpression' => true,'method' => 'post','data'=>'$(\'#query,#criteria\').serializeArray()')
),false);
?>
</script>
The above Js should grab the values of the criteria drop down aswell as the value inside the input field , on the keyup event. That said, I thought it was better to encode the data, and found the serializeArray method in the doc, which should do just that (I think..)
Now, my problem is I do not know how to retrieve that serialized data from the action receiving the request. So far I have this
function search() {
if($this->request->is('post')){
$data = $this->request->input('json_decode');
}
}
So basically, I want to know how to access the data from the search action, as well as, I tried to echo the $data variable, and die($data), but I do not know where the debugging info is displayed. Any help regarding both my questions would be MUCH appreciated! thanks!
I'm designing a custom adminhtml grid based on a model of my own, I've added an actions column to the grid which I'd like to be able to click to copy some text to the clipboard.
So in the _prepareColumns() function in Grid.php, I've added the actions column as seen below:
$this->addColumn('action',array(
'header' => Mage::helper('sales')->__('To Clipboard'),
'width' => '5%',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'is_system' => true,
)
);
I'd likely need to use Javascript to do this, but I'm not quite sure how to. Using the method above strangely enough also causes a page reload, even though I have successfully added $this->setUseAjax(true); to __construct();.
Would appreciate some input.
There are some interesting things you can do here. Mainly, you will want to reference the Action renderer and the Grid Javascript. The code you have right now should render a single link in the actions column. However, if you provide an array of actions, this will become a <select> list. When a <select> is rendered, then the grid.js file is responsible for performing the action.
Below are some examples of what you would pass in the 'actions' array:
Javascript Onclick w/ link
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'onclick' => 'window.location = "' . Mage::getUrl('*/*/toclipboard') . '"'
)
),
...
Confirm before running action
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'confirm' => true
)
),
...
Render a <select> list of actions (open last action in a popup)
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'confirm' => true
),
array(
'caption' => Mage::helper('sales')->__('Example'),
'onclick' => 'window.location = "' . Mage::getUrl('*/*/toclipboard') . '"'
),
array(
'caption' => Mage::helper('sales')->__('Popup'),
'popup' => true
'url' => array('base'=>'*/*/toclipboard'),
)
),
...
#Franklin P Strube: ty, pointed me in the right direction.
Final solution I used was as follows
....
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'onclick' => "javaScriptCopyMethod();"
)
),
....
It is considered bad practice to access a user's clipboard and most browsers prevent this nowadays, I did however find an extremely creative post linked below explaining how Trello "appears" to access the users' clipboard, the solution was actually posted by Daniel LeCheminant who is one of the Trello developers.
Solution: How does Trello access the user's clipboard?
Additional: https://trello.com/daniel
Simple add a option : 'target'=>'_blank'
Example :
$this->addColumn('action',
array(
'header' => Mage::helper('revocation')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => '',
'actions' => array(array(
'caption' => Mage::helper('revocation')->__('View'),
'url' => array('base' => 'adminhtml/sales_order/view'),
'field' => 'order_id',
'target'=>'_blank'
)),
'filter' => false,
'sortable' => false,
'index' => 'order_id',
));
I have a select box, and I want to use it to Ajax-update some other content on the page. So I have bound an event handler using the JsHelper (jQuery) like so:
<?php
echo $this->Form->select('car', $cars);
$this->Js->get("#car");
$this->Js->event('change', $this->Js->request(array(
'controller' => 'cars',
'action' => 'view',
???,
array('async' => true, 'update' => '#car-view', 'evalScripts' => true),
true
));
?>
But how can I get the value of the select box to send as an argument to the cars controller (at "???" in the code above)?
I could do everything in javascript, but is there any way to do this in cake?
To be honest, I struggled with this a while back. I couldn't find anything that worked, so I ended up just going the straight javascript route.
I think you are looking for this:
$this->Js->get('#selectbboxid1')->event('change',
$this->Js->request(array(
'action' => 'function'), array(
/*'before' => 'showLoader();',
'success' => 'hideLoader();',*/
'update' => '#selectboxid2',
'dataExpression'=>TRUE,
'method'=>'POST',
'async'=>TRUE,
'data' => $js->serializeForm(array('isForm' => TRUE, 'inline' => TRUE)) )));