I am trying to add new functionality to Storelocator module. I
have added new checkbox in admin and create new column in database
table. Saving checkbox value to databse is working. Now I want to print "recommended" value, but nothing happens. Why?
Checkbox field /Sparx/Storelocator/Block/Adminhtml/Storelocator/Edit/Tab/Form.php
$fieldset->addField('recommended', 'checkbox', array(
'label' => Mage::helper('storelocator')->__('Recommended'),
'onclick' => 'this.value = this.checked ? 1 : 0;',
'required' => false,
'name' => 'recommended',
'value' => '0',
));
Printing value /Sparx/Storelocator/controllers/IndexController.php
<div class="list-content">
<div class="loc-name">{{name}}</div>
<div>{{recommended}}</div>
<div class="loc-addr">{{address}}</div>
<div class="loc-addr3">{{city}}, {{state}} {{country}} {{postal}}</div>
<div class="loc-phone">{{phone}}</div>
<div class="loc-web">{{web}}</div>
{{#if distance}}<div class="loc-dist">{{distance}} {{length}}</div>
<div class="loc-directions">Directions</div>{{/if}}
{{#if storeid}}<div class="loc-desc">Store Details</div>{{/if}}
Related
I have created a dev that is changed according to the selected radio button.
the dev has input fields:
<div id='div-cash' class="toHide" hidden="true">
<div class="row" >
<div class="col-md-4">
<?php echo $form->field($cash[0], 'form_get',[
'template' => '{label}<div class="input-group">{input}
<span class="input-group-addon">pt</span></div>{error}{hint}',
'options' => ['class' => 'form-inline toHide cashtoHide', 'style' => 'margin-top:2rem'],
'labelOptions' => ['style' => 'margin-right:2rem'],
])->textInput();?>
</div>
</div>
</div>
when I submit the form the inputs of the other options are validated and I want to disable it
I used Conditional Validation to solve this problem
'whenClient' => "function (attribute, value) {
return $('input[type=radio]:checked').val() == 'cash';
}"
I want radio button within table, without label and one radio button for one table row, while all grouped in one single group, so user can select single table row by selecting one radio button from the group ...
In pure html it looks like this:
<div class="radio">
<label>
<input type="radio" name="memberPaymentsRadio" value="mp<?php echo $key;?>" aria-label="...">
</label>
</div>
What would be the code in cakephp to get the same html code?
I tried like this:
foreach($payments as $key => $payment){
...
echo $form->input('memberPaymentsRadio',
array(
'div' => array('class' => 'radio'),
'label' => false,
'type' => 'radio',
'aria-label' => '...',
'options' => array('mp'.$key),
'before' => '<label>',
'after' => '</label>'
)
);
}
but I'm getting radio buttons, one per table row, and all within specific table column, but with labels 'mp0', 'mp1', which is not what I was looking for...
You can use like this
$this->Form->radio('memberPaymentsRadio', array('mp'.$key => ""),array('class' => 'radio', 'before' => '<label>','after' => '</label>','label' => false));
I have three buttons which open 1 modal window on a page:
<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'myModal',)); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4 class="text-center">Pay</h4>
</div>
<div class="modal-body">
<?php
$this->widget('bootstrap.widgets.TbDetailView', array(
'type'=>'bordered condensed',
'data'=>$model,
'attributes'=>array(
array(
'type'=>'raw',
'label'=>'Период',
'value'=> '', // if (clicked button id is 1 value == 1 day) else if (clicked button id is 2 value == 7 days)
),
),
));
?>
</div>
<div class="modal-footer">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'type'=>'primary',
'label'=>'Проверить',
'url'=>'#',
'htmlOptions'=>array('data-dismiss'=>'modal'),
)); ?>
</div>
<?php $this->endWidget(); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'1 day',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '1',
'onclick' => 'alert(this.id)',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'7 dayss',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '2',
'onclick' => 'alert(this.id)',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array(
'encodeLabel' => false,
'label'=>'1 month',
'type'=>'primary',
'htmlOptions'=>array(
'id' => '3',
'data-toggle'=>'modal',
'data-target'=>'#myModal',
),
)); ?>
How to pass the clicked button id to TbButton value?
if (clicked button id is 1 value == 1 day) else if (clicked button id is 2 value == 7 days) ...
First of all, id of elements on website need to be unique, you may want to consider using data attributes or calling those id differently.
Next thing is that only button that is submitting form is passing value with form to the server so you either need to use hidden input field or submit form by pressing that button or submit form using ajax request and attach it manually.
As I see you have put onclick event directly in element, better solution would be to put it outside in separate script tag/script file, but it is outside of your question.
What you need to do to assign value to be sent with form is to use following js to:
Assign code to input field:
$('#length_field').val(this.id)
or without jQuery:
document.getElementById('length_field').value = this.id
if you will use data-time-length="7" instead of id then you can do it by:
$('#length_field').val($(this).data('time-length'))
However it is unclear to me where you want to pass this value, what you want to do with it.
I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list
I'm having problem about making the second dropdown hide/unhide if the selected item is the 1st choice of the first dropdown. Since this is more of front-end, I figured I'd use AJAX.
I'm using X-editable widget, here's the code:
<div class="control-group">
<label class="control-label" for="category">大カテゴリ</label>
<div class="controls">
<?php
$criteria = new CDbCriteria;
$criteria -> condition = 'parent_id=:parent_id AND school_id=:school_id AND status=:status';
$criteria -> params = array(':parent_id' => 0, ':school_id' => $school_account_info -> id, ':status' => 'active');
?>
<?php
$this->widget('editable.EditableField', array(
'id' => 'drop', //ADDED THIS LINE SO I COULD GET THE SELECTED VALUE BUT I GUESS I'M WRONG
'type' => 'select',
'model' => $model,
'attribute' => 'category',
'url' => '/school/Materials_Photos/View',
'source' => Editable::source(AssetCategory::model()->findAll($criteria),'id','category'),
'placement' => 'right',
));
?>
</div>
</div>
//SECOND DROPDOWN (SAMPLE ONLY)
<div class="control-group" id="sub_category" style="display: none">
<label class="control-label" for="category">中カテゴリ</label>
<div class="controls">
<?php echo CHtml::dropDownList('sub_category', '', array(), array('prompt' => 'Select')); ?>
</div>
</div>
But then I saw this:
<script>
$(function(){
$('#status').editable({
value: 2,
source: [
{value: 1, text: 'Active'},
{value: 2, text: 'Blocked'},
{value: 3, text: 'Deleted'}
]
});
});
</script>
and I thought this is more practical, I just couldn't figure how to get the source from ActiveRecord through JS.
Check validate callback. May be it will help you. validate will trigger when you click on the OK button.
Read here. http://x-editable.demopage.ru/index.php?r=site/widgets#Options
Try like this
<?php
$this->widget('editable.EditableField', array(
'id' => 'drop', //ADDED THIS LINE SO I COULD GET THE SELECTED VALUE BUT I GUESS I'M WRONG
'type' => 'select',
'model' => $model,
'attribute' => 'category',
'url' => '/school/Materials_Photos/View',
'source' => Editable::source(AssetCategory::model()->findAll($criteria), 'id', 'category'),
'placement' => 'right',
'validate' => 'js: function(value)
{
console.log(value); //The value you are selecting from x-editable dropdown
if($.trim(value) == "Somthing")
{
//Your functionality
}
}'
));
?>
Could you not simply use jQuery for this?
$(document).ready( function() {
var drop1val = $(".drop1").val();
if (drop1val == "first")
{
$(".drop2").hide();
} else {
$(".drop2").show();
}
});
I'm not sure what the x-editable widget is, I'd just assume however in terms of a general html form, my code should work. Something to think about at the very least.
If your code generates a dropdown list, by creating a then would it be possible for you to add a class or id to that tag?