SlickGrid error: Slick.Editors.Text is not a constructor - php

I'm trying to implement SlickGrid on the edit page of a CakePHP project, and when the page loads I get this error in the javascript console:
slick.grid.js:2173TypeError:'Slick.Editors.Text is not a constructor' (evaluating 'new (editor || getEditor(activeRow, activeCell))')
The data renders correctly in the grid on my page, but when I click on a cell to edit it, it just turns white and I can't type anything. If I click on another cell, that cell will turn white and the first one will stay white.
Here is my php/jQuery code:
<?php echo $this->Html->script("/js/slickgrid/lib/jquery-1.7.min.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/lib/jquery.event.drag-2.0.min.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/lib/jquery-ui-1.8.16.custom.min.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/slick.core.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/slick.grid.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/slick.editors.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/slick.formatters.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/slick.dataview.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/plugins/slick.cellselectionmodel.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/plugins/slick.cellrangedecorator.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/plugins/slick.cellrangeselector.js"); ?>
<?php echo $this->Html->script("/js/slickgrid/plugins/slick.rowselectionmodel.js"); ?>
<?php // Setup rows and cols array for grid
$columns = array();
foreach($route['Stop'] as $stop) {
$columns[] = array( "name" => $stop['name'],
"field" => $stop['id'],
"id" => $stop['id'],
"editor" => "Slick.Editors.Text");
}
$tripId = 1;
$thisTrip['id'] = $tripId;
foreach($route['RouteTrip'] as $routeTrip) {
if($routeTrip['trip_id'] != $tripId) {
$rows[] = $thisTrip;
$tripId = $routeTrip['trip_id'];
$thisTrip['id'] = $tripId;
}
else {
$thisTrip[$routeTrip['stop_id']] = $routeTrip['time'];
}
}
?>
<?php
echo $this->Html->scriptBlock('
var rows = '.json_encode($rows).';
var columns = '.json_encode($columns).';
var options = { rowHeight:21,
defaultColumnWidth:100,
editable:true,
enableAddRow:true,
enableCellNavigation:true,
asyncEditorLoading:false,
autoHeight:true,
autoEdit:true
};
slickgrid = new Slick.Grid($("#scheduleTable"), rows, columns, options);
slickgrid.setSelectionModel(new Slick.CellSelectionModel());
slickgrid.updateRowCount();
slickgrid.render();
');
?>
The $rows and $columns are correctly formatted, and each column has an "editor" attribute with "Slick.Editors.Text" as its value.
Help?

I have also got this error initially when i started working with slickgrid.
The error is because you have specified the editor as string and not as a class.
So, remove the double quotes in "editor" => "Slick.Editors.Text" and give as "editor" => Slick.Editors.Text
This solved the error for me. Hope this solution will solve yours too.

Include the slick.editors.js file.
Also, make sure that the editor is being specified as a class, not as a string (I'm not familiar with PHP, so it's not obvious to me from the source code, but I suspect that's the case).

Related

Isssue with display data from database

I use framework:
CodeIgniter
I try display values from enrol table. Connetcion with DB working correct etc. Because standard app function in this way working correct. I try add my custom own code but something went wrong and result is empty.
I try combinate in this way:
<?php
$enrol_history = $this->db->get_where('enrol', array('active_shop' => $active_shop, 'monthly_subscription_fee' => $monthly_subscription_fee))->row_array();
?>
<?php echo $active_shop['active_shop']; ?>
<?php echo $enrol_history['monthly_subscription_fee']; ?>
<?php echo $active_shop ?>
<?php echo $monthly_subscription_fee ?>
Everytime empty result.
update:
I also try:
Crud_model.php
public function get_installation_details($monthly_subscription_fee = "")
{
return $this->db->get_where('enrol', array('monthly_subscription_fee' => $monthly_subscription_fee));
}
code:
<?php $installation_details = $this->crud_model->get_installation_details($monthly_subscription_fee)->row_array(); ?>
<?php echo $installation_details['monthly_subscription_fee']; ?>
update:
<?php
$enrol_history = $this->db->get_where('enrol', array('active_shop' => $enrol['active_shop'], 'monthly_subscription_fee' => $enrol['monthly_subscription_fee'],))->row_array();
?>
<?php echo $enrol['monthly_subscription_fee']; ?>
<?php echo $enrol['active_shop']; ?>
This is correct. Because in admin panel I can get in this way this values from DB. But in frontend I cannot do it...

How to insert php code inside javascript

Kindly pls have a look at the code below ! Its working perfectly except the php code is not giving any output. When i insert the output of the php , the script work perfectly.
<script type="text/javascript">
function LoadVideoBar() {
var videoBar;
var barContainer = document.getElementById("videoBar");
var options = {
largeResultSet : false,
horizontal : true,
autoExecuteList : {
cycleTime : GSvideoBar.CYCLE_TIME_SHORT,
cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
executeList : [ "<?php $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_name; echo "-"; echo wp_title(); ?> "]
}
}
new GSvideoBar(
document.getElementById("videoBar"),
document.getElementById("videoPlayer"),
options
);
}
GSearch.setOnLoadCallback(LoadVideoBar);
When i replace the php code
<?php $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_name; echo "-"; echo wp_title(); ?>
with some text like : categoryname-title name
The script works perfectly.
Can somebody help me out with this small issue ...
Many Thanks in Advance!
If you ever need to pass data between the two. Put the PHP value into a hidden field. then read it like you did with bar container
Save the value from PHP:
<?php $cat = get_the_category(); $cat = $cat[0]; ?>
<input id="executeListValue" type="hidden"
value="<?php echo $cat->cat_name."-".wp_title();?>" >
read it in js:
var executeListValue = document.getElementById("executeListValue").value;
//...
autoExecuteList : {
cycleTime : GSvideoBar.CYCLE_TIME_SHORT,
cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
executeList : executeListValue
}
if the php code is replaced and the script works fine means php is having some error while executing. can you please try to see the source code of the html page. this may be happening because of some php error happening and those error message string could be making some syntax error to javascript.
try to put the php code outside the javascript tag and see the output generated from it.
<?php
$cat = get_the_category();
$cat = $cat[0];
$output= $cat->cat_name."-".wp_title();
?>
and then try to print the output in the javascript.
executeList : [ "<?php print $output; ?>"]
}
by this way you can see if any php error is encountered.
Replace "-" with '-' in Javascript code in line:
[ "<?php $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_name; echo "-"; echo wp_title(); ?> "]

WP Custom Fields, hide code if field is empty?

I'm using a custom field template plugin for WP. I want to hide
<li>Sqft: [squareft]</li>
if the field is empty. I've tried different codes, these are two I've tried based on suggestions:
<?php if ('squareft' !== '') { ?><li>Sqft: [squareft]</li>
<?php } ?>
And
<?PHP $squareft = ('squareft'); if ($squareft != '') { echo '<li>Sqft: [squareft]
</li>';} if (empty($squareft)) { echo " "; } ?>
I obviously don't have a clue what I'm doing, although I'm learning through trial and error. It uses shortcodes, so [squareft] is what to use to output the field data.
Any help is appreciated.
Update:
I think I've got it working, based on doing this method. Not yet gone live but it's working in my test post.
<?php
global $post;
$bathrooms = get_post_meta($post->ID, 'bathrooms', true);
if ( !empty($bathrooms) ) { echo '<li>Baths: [bathrooms]</li> | ' ; }
?>
Try this (replacement of the if statement in your first code sample):
<?php if (do_shortcode('[squareft]') != '') { ?>
<li>Sqft: [squareft]</li>
<?php } ?>
Or if you know the custom meta field's actual field name (generated by the plugin, probably some kind of prefix + squareft) you can do:
<?php if (get_post_meta($post->ID, 'squareft', true) != '') { ?>
It would help to know the specific plugin you are using.
Using the get custom fields plugin I have used the following to hide content if the field it empty (in this case the 'info' field):
<?php $info = c2c_get_custom('Info');?>
<?php if ( $info == "" ) {echo "";} else {echo "<h2 id=comments>Notes</h2><div id=info>$info</div>" ;} ?>
Not sure if this will help but it might give someone else more ideas.
Are tring this :
<?php if ( (c2c_get_custom('image')) ) { ?>
blah blah blah php code etc...
<?php } ?>
Works perfectly. If field has something it shows, if not no show, it was leaving a broken image when empty, now its good.
<?php if (get_post_meta($post->ID, 'squareft', true) != '') { echo "display output";?>

Yii multi model with HAS_MANY Tabular form

I have been trying to find a solution to something that I believe is rather simple? What I would like to do is create a tabular form to collect some records for a survey.
Table: survey_record
id
meter_id
status_id
create_time
create_user
Table: survey_inspection
id
survey_record_id (FK)
bay_id
bay_usage_id
So table survey_inspection HAS_MANY inspections from survey_record.
Assuming an inspector is doing a survey for meter_id = 1001, the user identifies the status_id of the meter then, they have to fill in 4 inspection entries, as 1001 has 4 bays.
To generate the 4 bays I simply created a for loop. Which works fine.
View: _form.php
...
$meter=Meter::model()->findByPk($model->meter_id);
$bays = count($meter->bays); //retrieves the number of inspections required
<?php echo $form->dropDownListRow($model,'status_id',$model->getStatusId(),array('prompt'=>'Select Status ...')); ?>
...
<?php for ($i = 1; $i <= $bays; $i++): ?>
<?php echo $form->textFieldRow($inspection, "[$i]bay_id", array('readonly'=>true, 'value'=>"$i", 'class'=>'span1')); ?>
<?php echo $form->dropDownListRow($inspection, "[$i]bay_usage_id", $inspection->getUsageId(), array('prompt'=>'Bay Status ...') ); ?>
<?php endfor; ?>
...
However when I submit the form I am only receiving two (not four) results and I can't seem to display the validated fields correctly. So here's the famous controller file:SurveyRecordController.php
public function actionCreate($survey_id, $meter_id)
{
$model=new SurveyRecord;
$inspection = new SurveyInspection;
$model->survey_id = (int)$survey_id;
$model->meter_id = (int)$meter_id;
if(isset($_POST['SurveyRecord'], $_POST['SurveyInspection']))
{
$model->attributes=$_POST['SurveyRecord'];
$valid= $model->validate();
$i=1;
foreach($_POST['SurveyInspection'][$i] as $inspection)
{
$inspection = new SurveyInspection;
$inspection->bay_id =$_POST['SurveyInspection'][$i]['bay_id'];
$inspection->bay_usage_id =$_POST['SurveyInspection'][$i]['bay_usage_id'];
$valid= $inspection->validate() && $valid;
echo '<br/><br/><br/><pre>';
print_r($_POST['SurveyInspection'][$i]);
echo '</pre>';
if($valid)
{
if($model->save(false))
{
$inspection->survey_record_id = $model->id;
$inspection->save(false);
$this->redirect(array('/meter'));
}
}
$i++;
//$inspection->attributes=$_POST['SurveyInspection'][$i];
}
}
$this->render('create',array(
'model'=>$model,
'inspection'=>$inspection,
));
}
I have a funny feeling that I may not be doing the foreach loop correctly as when I view the array $_POST['SurveyInspection'][$i] I am only returned with two entries when there should be four.
Some information that may be helpful:
PHP version: 5.4.14
Yii version: 1.1.13
PostgreSQL version: 9.1.9
Thank you kindly :)
To my knowledge i think for the validation u have bypassed the default validation by passing
false to save method (ex : $model->save(false)) and u are also using yii's validate function . I think u try removing the false parameter and just use save() for the validation issue
The foreach loop is wrong. You can make it proper and a bit cleaner:
foreach($_POST['SurveyInspection'] as $i => $value)
{
$inspection = new SurveyInspection;
$inspection->bay_id = $value['bay_id'];
$inspection->bay_usage_id = $value['bay_usage_id'];
...
$i++ is not needed, as foreach will loop every element.
I've taken a completely different approach, valuable suggestions are always welcome :)
Hope this will be helpful for some of you.
Controller:
public function actionCreate($survey_id, $meter_id)
{
$bays = $this->getBayCount($meter_id);
for ($i=1;$i<=$bays;$i++)
{
$model=new SurveyRecord;
$model->survey_id = (int)$survey_id;
$model->meter_id = (int)$meter_id;
${'inspection_'.$i} = new SurveyInspection($i);
if(isset($_POST['SurveyRecord'], $_POST["SurveyInspection"][$i]))
{
$model->attributes = $_POST['SurveyRecord'];
${'inspection_'.$i}->attributes = $_POST["SurveyInspection"][$i];
echo '<br/><br/><br/><pre>';
print_r(${'inspection_'.$i}->attributes);
echo '</pre>';
}
}
for ($i=1;$i<=$bays;$i++)
{
${'inspection_'.$i} = new SurveyInspection($i);
$inspection['inspection_'.$i] = ${'inspection_'.$i};
}
$this->render('create',array(
'inspection'=>$inspection,
'model'=>$model
));
}
View:
...
<div class="control">
<?php echo $form->dropDownListRow($model,'status_id',$model->getStatusId(),array('prompt'=>'Select Status ...')); ?>
<?php
$meter=Meter::model()->findByPk($model->meter_id);
$bays = count($meter->bays);
?>
<?php for ($i=1; $i<=$bays; $i++): ?>
<table>
<tr>
<td><?php echo $form->textFieldRow($inspection["inspection_$i"], "[$i]bay_id",
array('readonly'=>true, 'value'=>"$i", 'class'=>'span1')); ?></td>
<td><?php echo $form->dropDownListRow($inspection["inspection_$i"], "[$i]bay_usage_id", $inspection["inspection_$i"]->getUsageId(),
array('prompt'=>'Bay Status ...') ); ?></td>
</tr>
</table>
<?php endfor; ?>
</div>
...
Credit: http://yiiblog.info/blog/index.php/post/108/Rename+ACtiveRecord+$_POST+array's+Name+to+update+multimodels
Note: There's still some work to be done on the view/controller (doesn't seem to be able to select on $_POST for my dropdowns on second model), will post once I have fixed it.
Thanks for your help #PeterM and #Ninad for your input.

Default Option and returning NULL

Trying to figure out how to better write this chunk of code. I'm wanting to get the list of the roster members and then create an array of options for the view dropdown to display inside the select dropdown and also have it have an option to display "Please Select An Option". However what if what is returned from the getAllRoster function is NULL which is what I have returned if no results are returned from a query. How should I handle that which I just want the empty option displayed.
Also I need to think about is do a function to retrieve all the allies for that specific matter and then display that ally as the default ally in the dropdown for each dropdown.
Controller:
$rosterList = $this->bios->getAllRoster();
$allies = array();
$allies[''] = 'Please Select An Opion';
foreach ($rosterList AS $ally)
{
$allies[$ally->id] = $ally->rosterName;
}
View:
<?php echo form_label( 'Ally 1', 'ally1'); ?>
<div>
<?php echo form_dropdown( 'ally1', $allies, ''); ?>
</div>
<?php echo form_label( 'Ally 2', 'ally2'); ?>
<div>
<?php echo form_dropdown( 'ally2', $allies, ''); ?>
</div>
<?php echo form_label( 'Ally 3', 'ally3'); ?>
<div>
<?php echo form_dropdown( 'ally3', $allies, ''); ?>
</div>
EDIT :
What I am wanting to do is if the allies array is empty it needs to display the message No wrestlers in database but its instead giving me an error in my view file.
Controller:
pastebin.com/1Bf721zJ
View:
<?php echo form_label( 'Ally 1', 'ally1'); ?>
<div>
<?php if ($allies[''] == 'No Wrestlers In Database') {
echo $allies[''];
}
else {
echo form_dropdown( 'ally1', $allies, '');
} ?>
</div>
I also am curious about something. I have the alliesList variable that either has a value of a resultset or null and what I want to do if its a result set is have each of the allies be the default value in each of the dropdowns.
You could do something like this:
$rosterList = $this->bios->getAllRoster();
$allies = array();
if (empty($rosterList) {
$allies[] = 'nothing to display';
}
else
{
$allies[] = 'Please Select An Option';
foreach ($rosterList AS $ally)
{
$allies[$ally->id] = $ally->rosterName;
}
}
also in your view, if you don't want to display a drop down you could put a conditional in to display something else, e.g.:
<?php if ($allies[0] == 'nothing to display') {
echo $allies[0]
}
else {
echo form_dropdown( 'ally1', $allies, '');
} ?>
Im not sure i fully understand your question but if im right cant you just do
if $_GET['allies'] == "Please select an option"{
$something = Null
}
else{
$something = $_GET['allies']
}
and use $something where you would have used $_GET['allies']?

Categories