Prestashop Module Form creation - javascript

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/

Related

I want to validate after submission of the form but it also validate before submission of the form using jquery in drupal forms

In contact form having one radio button with two value email and phone I want to validate after submission of the form but it also validate before submission of the form using jquery in drupal forms..
In my form when i click email it show one email text field with error and hide phone text field similary i choose phone it show both email and phone text field but for phone text field only it shows error for email field it doesnot show error now i completed this work whats my prblm is before clicking submit button i change email and phone value it shows the error but i want to show the error after submitting the form only..
if you really insist on using jquery independently then you should put it in a function and call it with an onclick/onchange attribute:
$form['wayToContact'] = array(
'#type' => 'radios',
'#validated' => TRUE,
'#title' => t('Best way to contact'),
'#default_value' => 'Email',
'#options' => array('Email' => $this->t('Email'), 'Phone' => $this->t('Phone')),
'#attributes' => array(
'class' => array('required')
'onchange' => 'yourFunction(this)',
'onclick' => 'yourFunction(this)'
)
);
You should be able to use the #states property on your field to do what you are asking. You can add multiple validations and it will create all the jquery for you.
e.g.:
// Show the email field when email selected for radiofld
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'email'),
),
),
),
);
// Show error message for phone field
$form['phoneerr'] = array(
'#type' => 'markup',
'#markup' => 'No Phone selected',
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'email'),
),
),
),
);
// Show the phone field when phone selected for radiofld
$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'phone'),
),
),
),
);
// Show error message for email field
$form['emailerr'] = array(
'#type' => 'markup',
'#markup' => 'No Email selected',
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'phone'),
),
),
),
);

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

cakephp form input add attribute

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

three selects each based on previous jquery

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

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