cakephp form input add attribute - javascript

I'm trying to add custom tag to cakephp form input but it won't apply.
I am using Bootstrap switch
My code :
$this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'data-label-text' => $items,
'class' => 'form-control',
));
att: i want to add item names as a 'data-label-text'
this is working (with out other attributes)
$this->Form->checkbox('aaa', array('data-label-text'=>'new item out'));
Any idea ? help ?

Try this
$options = array(0 => 'new item out 1', 1 => 'new item out 2');
echo $this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'options' => $options,
'class' => 'form-control',
));

Related

All of Datepicker and Datecontrol is not working in activeForm Kartik

I have added datecontrol(kartik extension) in my activeForm of YII2, but it is not working.
It is shown in the activeForm, but when i click the cancel button and picker button, it has not any popup.
So I added the datecontrol and datepicker button to the out of activeForm
<?php
$form = ActiveForm::begin(
['type' => ActiveForm::TYPE_HORIZONTAL]);
echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 1,
'attributes' => [
'first_name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter First Name...', 'maxlength' => 255]],
// ............................
'created' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => DateControl::classname(),'options' => [
'type' => DateControl::FORMAT_DATETIME],
'ajaxConversion'=>false,
],
]
]);?>
I tested adding datepicker to out of the activeform with this code.
echo DateTimePicker::widget([
'name' => 'dp_3',
'type' => DateTimePicker::TYPE_COMPONENT_APPEND,
'value' => '23-Feb-1982 12:35 AM',
'pluginOptions' => [
'autoclose'=>true,
'format' => 'dd-M-yyyy HH:ii P'
]
]);
But the same, is shown but not working.
I think there was many js files(maybe 2 or more) and datepicker.js file is not working because of the another one.
But didn't know how to fix that.
Can anyone help me?

Prestashop Module Form creation

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/

In yii2 how to change Dropdown data as per role from?

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

Dropdown javascript onload

I have a dropdown menu, that has a onchange function. Once the function is executed it changes another dropdown menu.
I need to make it so it executes the script onload.
1st dropdown:
echo $form->field($model, 'company_id')->dropDownList($items_company, ['prompt' => 'Select Company', 'style' => 'width:400px;', 'onchange' => '
$.post("index.php?r=project/lists&id=' . '"+$(this).val(), function( data ) {
$( "select#project-client" ).html( data );
console.log("On change");
console.log(data);
});
',])->label('Company');
2nd dropdown:
echo '<label class="control-label">Company Client</label>';
echo Select2::widget([
'model' => $model,
'attribute' => 'client',
'theme' => Select2::THEME_BOOTSTRAP,
'options' => [ 'label' => 'Client',
'multiple' => true, 'style' => 'width:400px;', 'overwriteInitial' => true],
'pluginOptions' => [
'disabled' => false,
],
]);
This is what I tried:
$(document).ready(function () {
var currentProjectCompany = $('#project-company_id').val();
$.post("index.php?r=project/lists&id=' . '" + currentProjectCompany, function (data) {
$("select#project-client").html(data);
console.log("Company ID:");
console.log(currentProjectCompany);
console.log("Clients");
console.log(data);
});
});
Move the onchange code into its own function (it should be there anyway), and execute that function in the ready() function.
That way it will fire both onchange and onload.
I do the same check my code it may help you .But i use ajax and jquery.
For firs dropdown .
echo $form->dropDownListGroup(
$model 'id', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' => abc::getName($model->id),
'htmlOptions' => array(
'prompt' => 'Select Project',
'ajax' => array(
'type' => 'POST',
'url' => ( Yii::app()->createUrl('/' . $domain_name . '/qq/xyz/abc') ),
'update' => '#seconddropdownid',
//'dataType' => 'json',
'data'=>array('id'=>'js:this.value'),
)
),
),
)
);
in second dropdown :
echo $form->dropDownListGroup(
$project, 'tag', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' =>$this->getProjectTags(),
'htmlOptions' => array(
'prompt' => 'Select Tags',
),
)
)
);
on change of the second list you can update the the list-view of yii .

Magento adminhtml grid with javascript action column

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',
));

Categories