I am displaying form elements in my CGridView and would like datepicker, but it complains
CDataColumn and its behaviors do not have a method or closure named "widget".
I have modified DATEIN using the method described in Use a widget in a statically-called method However i think it works partially as when i do a sort or the datepicker does not work. its working only on initial load.
<script>
$(document).ready(function() {
/*
$("input[name*='DATEIN'] ").each(function(){
jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
});
*/
$("input[name*='datedone'] ").each(function(){
jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
});
});
</script>
<?php
$job = new Jobs();
$buttonPlus = CHtml::ajaxLink('Add New Line', $this->createUrl('addNewLine',array("id"=>$model->id)), array(
'type' => 'POST',
'data' => array('id' => $model->id),
'success' => 'function(html){ $.fn.yiiGridView.update("jobs-grid"); $.fn.yiiGridView.update("detailsseismic-grid"); $.fn.yiiGridView.update("details3d-grid"); }'
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'jobs-grid',
'dataProvider'=>$job->searchbyproject($model->PROJID),
'afterAjaxUpdate'=>'function(id,options){
$("#jobs-grid").children("table").children("thead").children("tr").children("th").children("a").each(function(){
$(this).click(function(){
var x = getQueryParams(this.href);
if($("#detailsgeoscan-grid").length)
$.fn.yiiGridView.update("detailsgeoscan-grid",{data:"sort="+x.sort});
else if($("#detailsseismic-grid").length)
$.fn.yiiGridView.update("detailsseismic-grid",{data:"sort="+x.sort});
else if($("#details3d-grid").length)
$.fn.yiiGridView.update("details3d-grid",{data:"sort="+x.sort});
});
});
$("#jobs-grid").children("div").children("ul").children("li").children("a").each(function(){
$(this).click(function(){
var x = getQueryParams(this.href);
if($("#detailsgeoscan-grid").length)
$.fn.yiiGridView.update("detailsgeoscan-grid",{data:"Detailsgeoscan_page="+x.Jobs_page});
else if($("#detailsseismic-grid").length)
$.fn.yiiGridView.update("detailsseismic-grid",{data:"Detailsseismic_page="+x.Jobs_page});
else if($("#details3d-grid").length)
$.fn.yiiGridView.update("details3d-grid",{data:"Details3d_page="+x.Jobs_page});
});
});
/*
$("input[name*=\'DATEIN\'] ").each(function(){
jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"]. '"});
});
*/
$("input[name*=\'datedone\'] ").each(function(){
jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"].'"});
});
}',
'summaryText' => '',
'columns'=>array(
array(
'name'=>'JOBNO',
'value'=>'CHtml::activeHiddenField($data, "[$row]JOBNO")' ,
'type'=>'raw',
'headerHtmlOptions' => array('style' => 'display:none;'),
'htmlOptions' => array('style' => 'display:none'),
'footer' => $buttonPlus,
'footerHtmlOptions'=> array('colspan' => '7'),
),
array(
'name'=>'NAME',
'value'=>'CHtml::activeTextField($data, "[$row]NAME", array("size"=>25))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'SEQ',
'value'=>'CHtml::activeTextField($data, "[$row]SEQ", array("size"=>15))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'DATEIN',
//'value'=>'CHtml::activeTextField($data, "[$row]DATEIN", array("size"=>10))' ,
'value' => function ($data, $row, $column) {
$controller = $column->grid->owner;
echo $controller->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$data,
'attribute'=>'DATEIN',
// additional javascript options for the date picker plugin
'htmlOptions'=>array(
'class'=>'datefield',
'id' => 'Jobs_'.$row.'_DATEIN',
),
'options' => array(
'dateFormat' => Yii::app()->params["localdate"],
)
),true);
},
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'header'=>"Process Complete <div id='checkboxgroup'> $processcompleteheader </div>",
'value'=>'$data->getcheckboxProcesses($row)',
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'name'=>'DATEDONE',
'value'=>'CHtml::activeTextField((count($data->jobsprocesscomplete)>0) ? $data->jobsprocesscomplete(array("order"=>"datedone desc")) : new Jobsprocesscomplete , "[$row]datedone", array("size"=>10))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
'sortable' => false,
),
array(
'name'=>'COMMENTS',
'value'=>'CHtml::activeTextField($data, "[$row]COMMENTS", array("style"=>"width:150px"))' ,
'type'=>'raw',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
array(
'header'=>'<a id="deletealljobs" title="Delete All Lines" onclick="deleteAllJob(\'1409099\')" href="#">X</a>',
'class'=>'CButtonColumn',
'template'=>'{delete}',
'footerHtmlOptions'=> array('style' => 'display:none'),
),
),
));
?>
I render it on from another view
$processcompleteheader = null;
foreach ($processstages as $k => $v) {
$processcompleteheader .= CHtml::Checkbox($k."_all",'',array("value"=>$k,"title"=>$v));
}
$lineListContent = "<div id='form_line_list'>
<div style='display: block;
left: 565px;
position: absolute;
top: 7px;'> " .CHtml::hiddenField("PROJID",$model->PROJID) . CHtml::hiddenField("id",$model->id) . CHtml::activeFileField(new Fileupload,'jobs', array('onChange'=>'showLoadDialog();submit(this)'))."<a id=clearfile href=# onclick='clearfile()' />X</a></div>";
$lineListContent .= $this->renderPartial("/jobs/_formJobsGridview",array("model"=>$model,"processcompleteheader"=>$processcompleteheader),true);
$lineListContent .= "</div>";
I think this question over here can help you out:
Use a widget in a statically-called method
Basically this widget can be called by the controller, but in your code you are trying to call it by the gridview.
Related
i'm facing an issue with the filter input box in CGridView. So the filter is showing the correct result after entering the search string in the filter input box and hitting enter, but the input box is getting cleared after the result is being shown. This makes it quite inconvenient for the user to see what they was searching for because the filter input box is empty while the grid shows the correct search results.
Here are the code.
entry view name ::newsReleases.php
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-news-grid-' . $id,
'itemsCssClass' => 'table table-striped',
'htmlOptions' => array(
'class' => 'news-datagrid',
),
'dataProvider' => $dataProvider->searchProductNews($symbol),
'filter' => $dataProvider,
'enableHistory' => false,
'ajaxUpdate' => 'product-news-grid-' . $id,
'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 5,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'summaryCssClass' => 'label label-warning',
'columns' => array(
array(
'name' => 'headlines',
'header' => 'Headlines',
'value' => function($data) {
return '<div class="product-news"> <a target="_blank" href="' . $data->link . '" > ' . $data->headlines . '</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'publish_date',
'header' => 'Date',
'value' => function($data) {
return '<span class="news-pub-date">' . $data->publish_date . '</span>';
},
'type' => 'raw',
)
)
));
?>
<!-- Now this script had to be included again in order to make the ajax sorting and pagination work, or else none of the ajax functionality is working. Remember when getting stuck with ajax update in grid views always use this script -->
<script type="text/javascript" src="/ProductAnalysis/assets/dd5f9a70/gridview/jquery.yiigridview.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
jQuery('[data-toggle=popover]').popover();
jQuery('body').tooltip({
"selector": "[data-toggle=tooltip]"
});
jQuery('#product-news-grid-' + $('#symbol-id').text()).yiiGridView({
'ajaxUpdate': ['product-news-grid-' + $('#symbol-id').text()],
'ajaxVar': 'ajax',
'pagerClass': 'pagination',
'loadingClass': 'grid-view-loading',
'filterClass': 'filters',
'tableClass': 'table table-striped',
'selectableRows': 1,
'enableHistory': false,
'updateSelector': '{page}, {sort}',
'filterSelector': '{filter}',
'url': '/ProductAnalysis/index.php/realTime/AjaxUpdateProductNews',
'pageVar': 'News_page',
'afterAjaxUpdate': function() {
jQuery('.popover').remove();
jQuery('[data-toggle=popover]').popover();
jQuery('.tooltip').remove();
jQuery('[data-toggle=tooltip]').tooltip();
$('#News_headlines').change(function() {
var inputVal = $(this).val();
$('#News_headlines').val(inputVal);
});
}
});
});
/*]]>*/
</script>
Here is the controller action named AjaxUpdateProductNews
public function actionAjaxUpdateProductNews() {
$dataProvider = new News();
$dataProvider->unsetAttributes();
if (isset($_GET['News'])) {
$dataProvider->attributes = $_GET['News'];
}
$id = explode("-", $_GET["ajax"]);
$realTime = RealTime::model()->findByPk($id[count($id) - 1]);
$this->renderPartial('_newsView', array(
'dataProvider' => new News(),
'symbol' => $realTime->symbol,
'id' => $realTime->id,
'headlines' => $_GET['News']['headlines'],
'publish_date' => $_GET['News']['publish_date']
));
}
and here is the view _newsView
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-news-grid-'. $id,
'itemsCssClass' => 'table table-striped',
'htmlOptions' => array(
'class' => 'news-datagrid',
),
'dataProvider' => $dataProvider->searchProductNewsSymbol($symbol, $headlines, $publish_date),
'filter' => $dataProvider,
'enableHistory' => false,
'ajaxUpdate' => 'product-news-grid-'. $id,
'ajaxUrl' => Yii::app()->createUrl('/realTime/AjaxUpdateProductNews'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 5,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'summaryCssClass' => 'label label-warning',
'columns' => array(
array(
'name' => 'headlines',
'header' => 'Headlines',
'value' => function($data) {
return '<div class="product-news"> <a target="_blank" href="'. $data->link .'" > '. $data->headlines .'</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'publish_date',
'header' => 'Date',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->publish_date .'</span>';
},
'type' => 'raw',
)
)
));
?>
Now like i said the filter is showing the result, but the input box is getting cleared after it shows the result. I tried to reinsert the val in the input box using jQuery's change() handler, but it doesn't works.
Please provide any sort of advice on how to retain the search string value in the filter box. Oh, btw other grids on the sites are working flawlessly, so its not a problem with missing files.
Thanks in advance,
Maxx
Ok i've made a mistake in the renderpartial code() which caused this error. Simply changing
'dataProvider' => new News() to 'dataProvider' => $dataProvider fixed the issue. Hope it helps someone who is facing the same issues.
The working controller code
public function actionAjaxUpdateProductNews() {
$dataProvider = new News();
$dataProvider->unsetAttributes();
if (isset($_GET['News'])) {
$dataProvider->attributes = $_GET['News'];
}
$id = explode("-", $_GET["ajax"]);
$realTime = RealTime::model()->findByPk($id[count($id) - 1]);
$this->renderPartial('_newsView', array(
'dataProvider' => $dataProvider,
'symbol' => $realTime->symbol,
'id' => $realTime->id,
'headlines' => $_GET['News']['headlines'],
'publish_date' => $_GET['News']['publish_date']
));
}
I have setup CGridView with CArrayDataProvider
Controller
//Get data for form dropdown:
$criteria = new CDbCriteria;
$criteria->select = 'status';
$criteria->group = 'status';
$status_get = Model::model()->findAll($criteria);
foreach ($status_get as $s) {
$status[$s->status] = $s->status;
}
if(!isset($_GET['ajax'])){
//Display empty array - show no data before user input
$rawData=array();
} else {
// Here I want to be able to create custom array based on user input (from SQL query)
$rawData=array();
}
$arrayDataProvider=new CArrayDataProvider($rawData, array(
'id'=>'id',
/* 'sort'=>array(
'attributes'=>array(
'id', 'status',
),
), */
'pagination'=>array(
'pageSize'=>50,
),
));
$params =array(
'arrayDataProvider'=>$arrayDataProvider,
'status'=>$status,
);
if(!isset($_GET['ajax'])) $this->render('byDay', $params);
else $this->renderPartial('byDay', $params);
And View:
<?php
/* #var $this RaportController */
$this->breadcrumbs = array(
'Raport' => array('/raport'),
'ByDay',
);
?>
<h1><?php echo $this->id . '/' . $this->action->id; ?></h1>
<div class="form">
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'person-form-edit_person-form',
'enableAjaxValidation' => false,
'htmlOptions' => array(
'onsubmit' => "return false;", /* Disable normal form submit */
'onkeypress' => " if(event.keyCode == 13){ send(); } " /* Do ajax call when user presses enter key */
),
)); ?>
<?php
if (isset($status)) {
echo CHtml::DropDownList('status', 'attribute', $status);
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'day',
'options' => array(
'showAnim' => 'fold',
'showOn' => 'both',
),
'htmlOptions' => array(
'style' => 'width:80px;vertical-align:top; margin-left:20px'
),
));
}
?>
<div class="row buttons">
<?php echo CHtml::Button('SUBMIT', array('onclick' => 'send();')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<script type="text/javascript">
function send() {
var data = $("form").serialize();
$.ajax({
type: 'POST',
url: '<?php echo Yii::app()->createAbsoluteUrl("raport/byDay"); ?>',
data: data,
success: function (data) {
},
error: function (data) { // if error occured
alert("Error occured.please try again");
alert(data);
}
// dataType:'html'
});
}
</script>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $arrayDataProvider,
'template' => "{items}",
'htmlOptions' => array(
'style' => 'margin:8px;'
),
'columns' => array(
array(
'name' => 'Order id',
'value' => 'CHtml::encode($data["order"])',
'htmlOptions' => array(
'style' => 'width:50px;'
)
),
array(
'name' => 'Status',
'value' => 'CHtml::encode($data["status"])',
),
array(
'name' => 'Timestamp',
'value' => 'CHtml::encode($data["change_ts"])',
),
),
));
?>
So I want user to select option from dropdown, select date and make SQL query from this values. Then I want to pass results to CGridView.
Please Help... I'm stuck
This is what gii generates:
Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('category-grid', {
data: $(this).serialize()
});
return false;
});
");
Use the $.fn.yiiGridView.update to update your grid.
I have a weird problem. I copied my website into production environment (from windows to ubuntu). I correct few big/small letter issues and app started to work fine. Until I entered one page that looks like it's being rendered without layout. There is no error.
Also - firebug shows no css styles or anything. At HTML source there is lack of layout code too.
What could be the reason of that?
EDIT:
controller part:
$dataProvider = Projects::model()->getInviteProjectsProvider();
$this->render('invite', array(
'dataProvider' => $dataProvider
));
It returns CActiveDataProvider.
View:
<?php
$this->breadcrumbs=array(
'Projekty' => array('admin'),
'Zapraszanie',
);
$this->renderPartial('_allMenu');
?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->module->assetsUrl; ?>/css/projects.css"/>
<h1>Projekty aktywne - zapraszanie</h1>
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id' => 'invite-grid',
'type' => 'striped condensed',
'dataProvider' => $dataProvider,
'rowCssClassExpression' => '($data->leftCustomers<100) ? "error":""',
'columns' => array(
array(
'name' => 'idProject',
'htmlOptions' => array('width' => '60px', 'style' => 'text-align: right;', 'class' => 'gridIdColumn'),
),
'name',
array(
'name' => 'leftCustomers',
'header' => 'Pozostało <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Gdy wartość ta jest mniejsza niż 100 - rekord jest podświetlony na czerwono"/>',
),
'confirmStart',
'presentationDate',
array(
'class' => 'bootstrap.widgets.TbRelationalColumn',
'name' => 'Statystyki',
'value' => '"Pokaż"',
'url' => $this->createUrl('dynamicProjectStats')
),
array(
'header' => 'Postęp <i class="icon-info-sign" rel="tooltipbootstrap" data-original-title="Liczba zaproszeń / Limit zaproszeń"/>',
'value' => function($data)
{
$prc = round(($data->projectMaxInvites > 0) ? ($data->projectInvites)/ $data->projectMaxInvites * 100 : 0, 2);
Controller::widget('bootstrap.widgets.TbProgress', array(
'percent' => $prc,
'htmlOptions' => array(
'style' => 'height: 20px; margin-bottom: -20px',
'rel' => 'tooltipbootstrap',
'data-original-title' => $prc." %",
),
));
},
),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => '{view}{update}{delete}',
'htmlOptions' => array(
'style' => 'width: 40px;',
),
),
array(
'header' => '',
'htmlOptions' => array('style' => 'width: 43px'),
'value' => function($data)
{
$this->renderPartial('partials/_actionMenu', array('idProject' => $data->idProject, 'activated' => true, 'afterAction' => 'removeActiveProject'));
}
),
array(
'header' => '',
'value' => function($data)
{
$this->renderPartial('partials/_statMenu', array('idProject' => $data->idProject, 'showIcon' => true));
}
),
)
));
?>
I noticed that if I comment out the columns where function($data) is used - it shows fine. When I leave it - there is no layout displayed.
EDIT2:
Maybe I should notice the fact that inside partials/_statMenu and partials/_actionMenu there is a bootstrap.widgets.TbButtonGroup widget rendered.
Try:
Yii::app()->controller->renderPartial(...)
Instead of:
$this->renderPartial(...)
How to Pop Up A New Windwon In Gridview?
When the use click the refund button of gridview, I would like to display the popup box with the data. How can I do?
This is the my gridview
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'advance-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name' => 'acc_category_id',
'value'=>'(isset($data->acccategories->name)) ? CHtml::encode($data->acccategories->status) :"Not Set"',
'filter'=>CHtml::listData($acccate, 'id', 'name'),
),
array('name' => 'accmain_id',
'value'=>'(isset($data->accmains->name)) ? CHtml::encode($data->accmains->name) :"Not Set"',
'filter'=>CHtml::listData($accmain, 'id', 'name'),
),
array('name' => 'job_id',
'value'=>'(isset($data->jobs->name)) ? CHtml::encode($data->jobs->name) :"Not Set"',
//'filter'=>CHtml::listData($job, 'id', 'name'),
),
'currency',
'amount',
array('name' => 'created_date',
'value'=>'Yii::app()->dateFormatter->format("d MMM y",strtotime($data->created_date))',
// 'filter'=>CHtml::listData($job, 'id', 'name'),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update} {delete} {refund}',
'buttons'=>array
(
'update' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/edit.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/update", array("id"=>$data->id))',
),
'delete' => array
(
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/delete.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/delete", array("id"=>$data->id))',
),
'refund' => array
(
'type'=>'raw',
'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_refund_loans2.gif',
'options'=>array('style'=>'width:10px; border:none;'),
'url'=>'Yii::app()->createUrl("advance/view", array("id"=>$data->id))',
),
),
),
),
'htmlOptions' => array(
//'class' => 'table table-bordered table-striped table_vam grid_widget',
),
)); ?>
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist"></div>
=====================================
update
when I update the grid by following and check by firebug, it is displaying the data at firebug. but not display popup.
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array("onclick"=>\'$("#jobslist").dialog("open"); return false;\'));',
),
This is controller
public function actionJobslist()
{
$model=new Job('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Customer']))
$model->attributes=$_GET['Customer'];
if(isset($_GET['AccRecei']))
$accrecei->attributes=$_GET['AccRecei'];
$this->renderPartial('jobs_listing',array('model'=>$model),false,true);
}
this is view/jobs_listing.php
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'jobslist',
'options'=>array(
'title'=>Yii::t('job','Jobs List'),
'autoOpen'=>true,
'modal'=>'true',
'width'=>'750',
'height'=>'500',
),
));
echo $this->renderPartial('_jobs_listing', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
how should I do?
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::link($data->id, array("id"=>$data->id, 'class'=>'view-popup'));',
),
and insert javascript:
$('.view-popup').live('click', function() {
var id = $(this).attr('id');
window.open("<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/your_path/id/'; ?>" + id,'popUpWindow','height=800,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
return false;
});
Inner of the grid
array(
'header'=>'Refund',
'type'=>'raw',
'value'=>'CHtml::ajaxLink($data->id, array("advance/jobslist", "id"=>$data->id), array(
"onclick"=>"$(\"#jobslist\").dialog(\"open\"); return false;","update"=>"#jobslist",
"beforeSend" => "function() {
$(\"#loadingdiv\").addClass(\"ajaxloading\");
}",
"complete" => "function() {
$(\"#loadingdiv\").removeClass(\"ajaxloading\");
}",
),array("id"=>"showcustomerlist2"));',
),
Out of the grid
<div id="loadingdiv" style="float:right; margin-right:160px;"> </div>
<div id="jobslist2"></div>
I am using Zend_Form and form validation. The issue is I am hiding some of the form fields using jQuery show() and hide() functions.
The problem here is that if the validation finds an error, all the form fields will show up and what I want is to keep the state of the hidden and visible fields. Any idea why this is happening?
If the code makes a difference please ask for it I will provide it immediately.
Zend_Form code:
$this->setMethod('post');
$element = new Zend_Form_Element_File("file", array(
'validators' => array(
array('Extension', true, 'hume')
)
));
$element->setDestination("/var/www/testGraduationProject1/public/TempFolder/");
$element->setLabel("Upload");
$this->addElement($element);
$this->addElement('submit', 'Upload', array(
'ignore' => true,
'label' => 'Upload',
));
$this->addElement('select', 'Work_Space', array(
'Multioptions' =>
array(
'Hume_Compile_Selection' => 'Please Select Compiling type',
'Hume_Recourses' => 'Hume Recourses',
'Hume_Compile' => 'Hume Compile',
),
'id' => 'Work_Space',
'label' => 'Compiler'
));
$this->addElement('select', 'Editor', array(
'Multioptions' =>
array(
'Choose Editor' => 'Choose Editor',
'TinyMce' => 'TinyMce',
'Ymacs' => 'Ymacs',
),
'id' => 'Editor',
'label' => 'Editor'
));
$this->addElement('text', 'File_Name', array(
'label' => 'File name',
'required' => true,
));
$this->addElement('checkbox', 'Advanced_Settings', array(
'checked' => '0',
'label' => 'Advanced Settings',
'id' => 'Advanced_Settings',
));
$this->addElement('textarea', 'Advanced_Options', array(
'label' => 'Advanced Options',
'cols' => 50,
'rows' => 7,
'id' => 'Advanced_Options',
'validators' => array(
array('regex', true, array(
'pattern' => '/[^[a-zA-Z ><+.,!##$%^&*()\"\'=]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'comment', array(
'label' => 'Hume Code',
'required' => true,
'class' => 'markItUp',
'id' => 'comment'
));
$this->addElement('checkbox', 'Few_Compile', array(
'checked' => '1',
'label' => 'Fewer Results',
'class' => 'Fewer_Results'
));
$this->addElement('submit', 'Compile_Recourses', array(
'ignore' => true,
'label' => 'Compile Recourses',
'class' => 'Compile_Recourses'
));
$this->addElement('radio', 'Time_Out', array(
'label' => 'Compiling Time',
'multiOptions' => array(
'5' => '5s',
'10' => '10s',
'15' => '15s',
),
'value' => array('5s' => '5s')
));
$this->addElement('checkbox', 'Compile_Advanced', array(
'checked' => '0',
'label' => "Set Heap Wire Stack Size's",
'id' => 'Compile_Advanced',
));
$this->addElement('textarea', 'Heap_Size', array(
'label' => 'Heap Size',
'Id' => 'Heap-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', true, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'Wire_Heap_Size', array(
'label' => 'Wire_Heap Size',
'Id' => 'Wire-Heap-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', false, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('textarea', 'Stack_Size', array(
'label' => 'Stack Size',
'Id' => 'Stack-Size',
'cols' => 5,
'rows' => 1,
'validators' => array(
array('regex', false, array(
'pattern' => '/[0-9]/',
'messages' => 'Please only numbers without spaces'
)
)
),
'attribs' => array('disabled' => 'disabled'),
));
$this->addElement('submit', 'Execute_Hume', array(
'ignore' => true,
'label' => 'Execute And Compile Hume',
));
$this->addElement('submit', 'Compile_Hume', array(
'ignore' => true,
'label' => 'Compile Hume',
));
// die($this->UserHasId);
if ($this->UserHasId) {
$this->addElement('submit', 'Save_File', array(
'ignore' => true,
'label' => 'Save File',
));
}
jQuery hide() and show() functions
<script type="text/javascript">
$(document).ready(function(){
$("#Advanced_Settings").click(function(){
if ($('#Advanced_Settings').is(':checked')) {
$('#Advanced_Options').removeAttr('disabled');
$('#Few_Compile').attr("disabled", "disabled");
} else {
$('#Advanced_Options').attr("disabled", "disabled");
$('#Few_Compile').removeAttr('disabled');
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#Compile_Advanced").click(function(){
if ($('#Compile_Advanced').is(':checked')) {
$('#Heap_Size').removeAttr('disabled');
$('#Wire_Heap_Size').removeAttr('disabled');
$('#Stack_Size').removeAttr('disabled');
} else {
$('#Heap_Size').attr("disabled", "disabled");
$('#Wire_Heap_Size').attr("disabled", "disabled");
$('#Stack_Size').attr("disabled", "disabled");
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var WorkSpace = $("#Work_Space").val();
if(WorkSpace == "Hume_Compile_Selection"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}
$("#Work_Space").change(function(){
var WorkSpace = $(this).val();
if(WorkSpace == "Hume_Recourses"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').show();
$('#Advanced_Settings-element').show();
$('#Advanced_Options-label').show();
$('#Advanced_Options-element').show();
$('#Few_Compile-label').show();
$('#Few_Compile-element').show();
$('#Compile_Recourses-label').show();
$('#Compile_Recourses-element').show();
}else if(WorkSpace == "Hume_Compile"){
$('#Time_Out-label').show();
$('#Time_Out-element').show();
$('#Compile_Advanced-label').show();
$('#Compile_Advanced-element').show();
$('#Heap_Size-label').show();
$('#Heap_Size-element').show();
$('#Wire_Heap_Size-label').show();
$('#Wire_Heap_Size-element').show();
$('#Stack_Size-label').show();
$('#Stack_Size-element').show();
$('#Compile_Hume-element').show();
$('#Execute_Hume').show();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}else if(WorkSpace == "Hume_Compile_Selection"){
$('#Time_Out-label').hide();
$('#Time_Out-element').hide();
$('#Compile_Advanced-label').hide();
$('#Compile_Advanced-element').hide();
$('#Heap_Size-label').hide();
$('#Heap_Size-element').hide();
$('#Wire_Heap_Size-label').hide();
$('#Wire_Heap_Size-element').hide();
$('#Stack_Size-label').hide();
$('#Stack_Size-element').hide();
$('#Compile_Hume-element').hide();
$('#Execute_Hume').hide();
$('#Advanced_Settings-label').hide();
$('#Advanced_Settings-element').hide();
$('#Advanced_Options-label').hide();
$('#Advanced_Options-element').hide();
$('#Few_Compile-label').hide();
$('#Few_Compile-element').hide();
$('#Compile_Recourses-label').hide();
$('#Compile_Recourses-element').hide();
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function(){
var count = 0;
var Editor = $("#Editor").val();
if(Editor == "Choose Editor"){
$('#File_Name-label').hide();
$('#File_Name-element').hide();
$('#File_Name').hide();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
}
$("#Editor").change(function(){
var Editor = $(this).val();
if(Editor == "TinyMce"){
$('#File_Name-label').show();
$('#File_Name-element').show();
$('#File_Name').show();
$('#comment-label').show();
$('#comment-element').show();
$('#comment').show();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
$('#accordionResizer').show();
if(count != 0){
$('#comment').hide();
$('#comment_parent').show();
}
if(count == 0){
$('#comment-label').show();
$('#comment-element').show();
$('#comment').show();
tinyMCE.init({
// General options
mode : "exact",
elements : "comment",
theme : "advanced",
skin : "o2k7",
skin_variant : "black",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
save_onsavecallback : "saveContent",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,forecolor,backcolor",
theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap,|,print,|,fullscreen,code",
theme_advanced_buttons4 : "styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : false,
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
count++;
}
}else if(Editor == "Choose Editor"){
$('#File_Name-label').hide();
$('#File_Name-element').hide();
$('#File_Name').hide();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').hide();
$('#ymacs-use').hide();
$('#accordionResizer').show();
}else if(Editor == "Ymacs"){
$('#File_Name-label').show();
$('#File_Name-element').show();
$('#File_Name').show();
$('#comment-label').hide();
$('#comment-element').hide();
$('#comment').hide();
$('#iframe-ymacs').show();
//$('#iframe-ymacs').contentWindow.location.reload(true);
// document.getElementById("#iframe-ymacs").contentDocument.location.reload(true);
//var iframe = document.getElementById("#iframe-ymacs");
//alert(iframe);
// iframe.src = iframe.src;
jQuery.each($("#iframe-ymacs"), function() {
$(this).attr({
src: $(this).attr("/index/editor")
});
});
$('#iframe-ymacs').attr('src', '/index/editor');
$('#ymacs-use').show();
$('#accordionResizer').hide();
//autoResize('#ymacs');
//$('#accordionResizer').hide();
}
});
});
</script>
If I understand, the form is posted, validated server side and when it has errors, it is populated and sent back to the user. Then, the user sees the form with the error message, am I right? If that is the case, you will need to trigger your Advanced_Settings and Compile_Advanced checkboxes to check if it should be displayed or not. Something like:
<script type="text/javascript">
$(document).ready(function(){
$("#Advanced_Settings").click(function(){
if ($('#Advanced_Settings').is(':checked')) {
$('#Advanced_Options').removeAttr('disabled');
$('#Few_Compile').attr("disabled", "disabled");
} else {
$('#Advanced_Options').attr("disabled", "disabled");
$('#Few_Compile').removeAttr('disabled');
}
});
$('#Advanced_Settings').click(); //This should trigger you checkbox click event
});
</script>
That should hide your advanced settings if the checkbox was not clicked when the form was first submitted.