Second dialog box doesn't show - php

I'm developping with Yii framework. I create two dialog boxes in a Yii page to create some model. The first one pops up correctly, but the second one doesn't.
I've written the view file. The view.php is as follow:
<?php
$this->menu=array(
//array('label' => Yii::t('app', 'Publier à un contact'), 'url' => array('publierAContact', 'id_p'=> $model->id_publication, 'id_e' => $model->id_evenement)),
array('label' => Yii::t('app', 'Publier à un contact'), 'url' =>'#','linkOptions' => array(
'onclick' => "{publierAContact(); $('#dialogContact').dialog('open');}",
)),
array('label' => Yii::t('app', 'Publier à un groupe'), 'url' => '#', 'linkOptions' => array(
'onclick' => "{publierAGroupe(); $('#dialogGroupe').dialog('open');}",
))
);
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogContact',
'options' => array(
'title' => 'Publier à un contact',
'autoOpen' => false,
'modal' => true,
'width' => 550,
'height' => 200,
),
));
echo "<div class='divForForm'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog');
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogGroupe',
'options' => array(
'title' => 'Publier à un groupe',
'autoOpen' => false,
'modal' => true,
'width' => 550,
'height' => 200,
),
));
echo "<div class='divForForm'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<script type='text/javascript'>
function publierAContact()
{
<?php echo CHtml::ajax(array(
'url' => array('Publication/PublierAContact', 'id_p'=>$id_p, 'id_e' =>$id_e),
'data' => "js:$(this).serialize()",
'type' => 'post',
'dataType' => 'json',
'success' => "function(data)
{
if(data.status == 'failure')
{
$('#dialogContact div.divForForm').html(data.div);
//Here is the trick: on submit-> once again this function!
$('#dialogContact div.divForForm form').submit(add);
}
else
{
$('#dialogContact div.divForForm').html(data.div);
setTimeout(\"$('#dialogContact').dialog('close');refreshDisciplines();\", 1000);
document.location.reload();
}
}"
));?>
return false;
}
function PublierAGroupe()
{
<?php echo CHtml::ajax(array(
'url' => array('Publication/PublierAGroupe', 'id_p' => $id_p, 'id_e' => $id_e),
'data' => "js:$(this).serialize()",
'type' => 'post',
'dataType' => 'json',
'success' => "function(data)
{
if(data.status == 'failure')
{
$('#dialogGroupe div.divForForm').html(data.div);
//Here is the trick: on submit-> once again this function!
$('#dialogGroupe div.divForForm form').submit(add);
}
else
{
$('#dialogGroupe div.divForForm').html(data.div);
setTimeout(\"$('#dialogGroupe').dialog('close');refreshDisciplines();\", 1000);
document.location.reload();
}
}"
));?>
return false;
}
</script>
Unfortunately, my second dialog can not appear. Can somebody help me know what's wrong ?
Edit :
The function must be called properly :
'onclick' => "{PublierAGroupe(); $('#dialogContact').dialog('open');}",
as the function's identifier is publierAGroupe.

Related

Form Validation in CakePHP 2

In my view I have
<?= $this->Form->create('Asc201516', array(
'url' => array(
'controller' => 'asc201516s',
'action' => 'submit_asc201516'
),
'class' => 'form-inline',
'onsubmit' => 'return check_minteacher()'
)); ?>
<div class="form-group col-md-3">
<?= $this->Form->input('bi_school_na', array(
'type' => 'text',
'onkeypress' => 'return isNumberKey(event)',
'label' => 'NA',
'placeholder' => 'NA',
'class' => 'form-control'
)); ?>
</div>
<?php
$options = array(
'label' => 'Submit',
'class' => 'btn btn-primary');
echo $this->Form->end($options);
?>
In my Controller, I have
$this->Asc201516->set($this->request->data['Asc201516']);
if ($this->Asc201516->validates()) {
echo 'it validated logic';
exit();
} else {
$this->redirect(
array(
'controller' => 'asc201516s',
'action' => 'add', $semisid
)
);
}
In my Model, I have
public $validate = array(
'bi_school_na' => array(
'Numeric' => array(
'rule' => 'Numeric',
'required' => true,
'message' => 'numbers only',
'allowEmpty' => false
)
)
);
When I submit the form, logically it should not get submitted and print out the error message but the form gets submitted instead and validates the model inside controller which breaks the operation in controller.
You have to check validation in your controller like
$this->Asc201516->set($this->request->data);
if($this->Asc201516->validates()){
$this->Asc201516->save($this->request->data);
}else{
$this->set("semisid",$semisid);
$this->render("Asc201516s/add");
}
You will have your ID there in variable $semisid, or you can set data in $this->request->data = $this->Asc201516->findById($semisid);

Yii menu linkOptions not working with ajax

I am trying to display a CGridView in a CJuiDialog but facing some problems.
In my view, I create a menu item as follow :
$this->menu = array(
array('label' => Yii::t('app', 'Afficher les participants ayant fourni cette information'),
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'linkOptions' => array(
//'onclick' => "{viewP(); $('#dialogViewP').dialog('open'); return false}",
'ajax' => array(
'type' => 'POST',
'url' =>"js:$(this).attr('href')", //array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'update' => '#divForForm2',
),
),
);
Then I've created the dialog :
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogViewP',
'options' => array(
'title' => 'Liste des participants ayant fourni cette information',
'autoOpen' => false,
'modal' => true,
'width' => 500,
'height' => 300,
),
));
?>
<div id="divForForm2"></div>
<?php $this->endWidget('dialogViewP'); ?>
And my controller looks like this one :
public function actionShowParticipantInfo($id){
$rows = Participant::findParticipantInfo($id);
$result = array();
foreach ($rows AS $key => $val){
$result[] = array('id' => $key +1, 'value' => $val['NomComplet']);
}
$arrayDataProvider = new CArrayDataProvider($result, array(
'id' => 'id',
'pagination' => array(
'pageSize' => 10,
),
));
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_showparticipant', array(
'arrayDataProvider' => $arrayDataProvider,
), false, true);
echo CHtml::script('$("#dialogViewP").dialog("open")');
Yii::app()->end();
}
}
But but clicking on the menu item, there is any dialog diplayed. I cannot know why. Can somebody help me ?
I think there should not be both 'url' and 'linkOption' attributes in an menu item. Either one.
Thru web dev tools you need to check if you have ajax XHR upon menu item click.
I'd recommend you this extention if you want to realize an ajax manu.
Even if you initiate ajax request the response cannot activate hidden dialog because on success you ONLY update certain div #divForForm2 but the dialog window is still closed: 'autoOpen' => false. I'd recommend incorporate opening dialog upon ajax success.
'ajax' => array(
'type' => 'POST',
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'success' =>'js:{function(data){$("#divForForm2").html(data); $("#dialogViewP").dialog("open");}'
),

Yii Cgridview Filter Input Box Not Showing Search String After Searching

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

integrated with JQGrid not loading data into custome edit JQForm

I am trying to integrate jqgrid and jqform but the data is not being populated into my jqform. I tested to make sure the jqgrid is passing over search key value for the form, and that works. But for some reason, my reform will not query correctly and populate form objects.
<?php
if(!isset($_SESSION))
session_start();
// Include class
include_once 'jqformconfig.php';
if(!class_exists('jqGridUtils'))
{
include_once $CODE_PATH.'jqUtils.php';
}
include_once $CODE_PATH.'jqForm.php';
$today = getdate(time());
$displayDate = $today['mon']."/".$today['mday']."/".$today['year'].' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds'];
$machrecs = null;
// Create instance
$newForm = new jqForm('MWOForm',array('action' => 'forms/mwoForm.php', 'method' => 'post', 'id' => 'MWOForm'));
// Demo Mode creating connection
if(!class_exists('jqGridDB'))
{
include_once $CODE_PATH.'/jqGridPdo.php';
}
$conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
$conn->query("SET NAMES utf8");
$newForm->setConnection( $conn );
// Set url
$newForm->setUrl($SERVER_HOST.$SELF_PATH.'forms/mwoForm.php');
// Set parameters
$mwo_id = jqGridUtils::GetParam('mwo_id',0901270825);
$mwo_id = is_numeric($mwo_id) ? (int)$mwo_id : 0;
$jqformparams = array($mwo_id);
// Set SQL Command, table, keys
$newForm->SelectCommand = 'SELECT mwo_id, asset_id, short_desc as machDesc
FROM mfg_eng_mwo.mwo
WHERE mwo_id =?';
$newForm->table = 'mfg_eng_mwo.mwo';
$newForm->setPrimaryKeys('mwo_id');
$newForm->serialKey = true;
// Set Form layout
$newForm->setColumnLayout('twocolumn');
$newForm->setTableStyles('width:500px;','','');
$statusSQL = 'SELECT distinct type FROM mfg_eng_mwo.wo_status';
$prioritySQL = 'SELECT distinct type FROM mfg_eng_mwo.wo_priority';
$deptSQL = 'SELECT dept_id FROM mfg_eng_mwo.department';
$deptData = '-1:Select a Department';
$machData = "";
$assetData = "";
$postData = "";
if(isset($row))
{
$deptData = "$row[dept]:$row[dept]";
$machData = "$row[asset_no]:$row[machDesc]";
$assetData =$row['asset_no'];
$postData = $row['post'];
}
$parts = '-:Order Parts?;1:YES;0:NO';
$tools = '-:Order Tools?;1:YES;0:NO';
// Add elements
$newForm->addElement('woStatus', 'select', array('label' => '<b>Status</b>', 'datasql' => $statusSQL, 'id' => 'woStatus', 'required'=>true));
$newForm->addElement('WOPriority', 'select', array('label' => '<b>Priority</b>', 'datasql' => $prioritySQL, 'id' => 'woPriority'));
$newForm->addElement('dept', 'select', array('label' => '<b>Deptartment</b>', 'datalist' => $deptData, 'datasql' => $deptSQL, 'id' => 'dept', 'required'=>true));
$newForm->addElement('machDesc', 'select', array('label' => '<b>Machine Desc</b>', 'datalist' => $machData, 'id' => 'machDesc','required'=>true));
$newForm->addElement('asset_id', 'text', array('label' => '<b>Asset ID#</b>', 'value' => $assetData, 'size' => '20', 'id' => 'MWOForm_asset_id', 'readonly'=>true, 'required'=>true));
$newForm->addElement('post', 'text', array('label' => '<b>Post</b>', 'value' => $postData, 'maxlength' => '40', 'id' => 'post', 'readonly'=>true, 'required'=>true));
$newForm->addElement('requester', 'text', array('label' => '<b>Requester</b>', 'value' => $_SESSION['user'], 'maxlength' => '60', 'id' => 'requester', 'readonly'=>true, 'required'=>true));
$newForm->addElement('enterTime', 'text', array('label' => '<b>Created</b>', 'value' => $displayDate, 'maxlength' => '15', 'size' => '20', 'id' => 'enterTime', 'readonly'=>true,'required'=>true));
//$newForm->addElement('short_desc', 'text', array('label' => '<b>Short Description</b>', 'maxlength' => '15', 'size' => '20', 'id' => 'short_desc', 'required'=>true));
//$newForm->addElement('parts', 'select', array('label' => '<b>Parts Needed</b>', 'datalist' => $parts, 'id' => 'parts', 'required' => 'true', 'hidden' => 'true'));
//$newForm->addElement('tools', 'select', array('label' => '<b>Tools</b>', 'datalist' => $tools, 'id' => 'tools', 'hidden' => 'true'));
$newForm->addElement('problem', 'textarea', array('label' => '<b>Problem</b>', 'rows' => "3", 'cols' => "50", 'id' => 'problem', 'required'=>true));
$newForm->addElement('solution', 'textarea', array('label' => '<b>Solution</b>', 'rows' => "3", 'cols' => "50", 'id' => 'solution'));
$elem_8[]=$newForm->createElement('newSubmit','submit', array('value' => 'Submit'));
$newForm->addGroup("newGroup",$elem_8, array('style' => 'text-align:right;', 'id' => 'newForm_newGroup'));
// Add events
$onchangeDept = <<< CHANGEDEPT
function(event)
{
$("#machDesc").show();
var deptval = $("#dept").val();
jQuery.ajax(
{
url: 'machine.php',
dataType: 'json',
data: {q:deptval},
success : function(response)
{
$('#machDesc').find('option').remove();
$('#machDesc').append('<option value=-1>Select Equipment</option>');
jQuery.each(response, function(i,mach)
{
$('#machDesc').append('<option value='+mach.asset_no+'>'+mach.asset_no+'::'+mach.short_desc+'</option>');
});
$('#asset_no').val('');
$('#post').val('');
}
});
}
CHANGEDEPT;
$newForm->addEvent('dept','change',$onchangeDept);
$onchangeMach = <<< CHANGEMACH
function(event)
{
var assetval = $("#machDesc").val();
jQuery.ajax(
{
url: 'post.php',
dataType: 'json',
data: {q:assetval},
success : function(response)
{
jQuery.each(response, function(i,mach)
{
$('#MWOForm_asset_id').val(mach.asset_no);
$('#post').val(mach.post);
});
}
});
}
CHANGEMACH;
$newForm->addEvent('machDesc','change',$onchangeMach);
$beforeSubmit = <<< BS
function(arr, form, options)
{
var toolval = $("#tool").val();
var partval = $("#part").val();
if(toolval == 0 || toolval == 1)
{
alert("Please select 'YES' or 'NO' for tools.");
return false;
}
if(partval != 1 || partval != 0)
{
alert("Please select YES or NO for tools.");
return false;
}
}
BS;
// Add events
$onclicknewButton = <<< CLICKNEWBUTTON
function(event)
{
if($("#ajax-dialog") ) {
$("#ajax-dialog").remove();
}
}
CLICKNEWBUTTON;
$newForm->addEvent('close_modal','click',$onclicknewButton);
// Add ajax submit events
$success = <<< SU
function( response, status, xhr) {
if(response=='success')
{
$("#grid").trigger("reloadGrid", [{current:true}]);
}
}
SU;
// Add ajax submit events
$newForm->setAjaxOptions( array('dataType'=>null,
'resetForm' =>false,
'clearForm' =>false,
'success' =>'js:'.$success,
'beforeSubmit' =>'js:'.$beforeSubmit,
'iframe' => false,
'forceSync' =>false) );
// Render the form
echo $newForm->renderForm($jqformparams);
?>
</body>

When Zend_Form validation, validate and find an error all the jQuery hidden fields show up?

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.

Categories