PDA

View Full Version : Editor Include help



VKPS
5 Nov 2006, 6:58 AM
Having a bit of a problem getting editable grids working. I got a normal grid working ok, but when I try this on my local machine I get an error:


<html>
<head>
<title>test</title>
<script type="text/javascript" src="yui/build/yahoo/yahoo.js"></script>
<script type="text/javascript" src="yui/build/dom/dom.js"></script>
<script type="text/javascript" src="yui/build/event/event.js"></script>
<script type="text/javascript" src="yui/build/dragdrop/dragdrop.js"></script>
<script type="text/javascript" src="yui/build/animation/animation.js"></script>
<script type="text/javascript" src="yui-ext.js"></script>
<link rel="stylesheet" type="text/css" href="grid.css"/>
</head>
<body>
<script>
EditorExample = function(){
var dataModel;
var grid;
var colModel;

var formatMoney = function(value){
value -= 0;
value = (Math.round(value*100))/100;
value = (value == Math.floor(value)) ? value + '.00' : ( (value*10 == Math.floor(value*10)) ? value + '0' : value);
return "$" + value;
};

var formatBoolean = function(value){
return value ? 'Yes' : 'No';
};

var formatDate = function(value){
return value.dateFormat('M d, Y');
};

var parseDate = function(value){
return new Date(Date.parse(value));
};

return {
init : function(){
var yg = YAHOO.ext.grid;
var cols = [{
header: "Common Name",
width: 160,
editor: new yg.TextEditor({allowBlank: false})
},{
header: "Light",
width: 130,
editor: new yg.SelectEditor('light')
},{
header: "Price",
width: 70,
renderer: formatMoney,
editor: new yg.NumberEditor({allowBlank: false, allowNegative: false, maxValue: 10})
},{
header: "Available",
width: 95,
renderer: formatDate,
editor: new yg.DateEditor({format: 'm/d/y', minValue: '01/01/06', disabledDays: [0, 6],
disabledDaysText: 'Plants are not available on the weekends',
disabledDates : ['^07', '04/15', '12/02/06'],
disabledDatesText : 'The plants are pollinating on %0, choose a different date.'})
},{
header: "Indoor?",
width: 55,
renderer: formatBoolean,
editor: new yg.CheckboxEditor()
}];
colModel = new YAHOO.ext.grid.DefaultColumnModel(cols);
colModel.defaultSortable = true;

var schema = {
tagName: 'plant',
id: 'use-index',
fields: ['common', 'light', 'price', 'availability', 'indoor']
};
dataModel = new YAHOO.ext.grid.XMLDataModel(schema);
dataModel.addPreprocessor(2, parseFloat);
dataModel.addPreprocessor(3, parseDate);
dataModel.addPreprocessor(4, Boolean);
dataModel.setDefaultSort(colModel, 0, "DESC");

grid = new YAHOO.ext.grid.EditorGrid('editor-grid', dataModel, colModel);
// to use double click to edit:
//grid.getSelectionModel().clicksToActivateCell = 2;
grid.render();

dataModel.load('plants.xml');
},

// filtering support, regex, function or text match
filter : function(e){
var mfilter = function(value){
return (value == 'Shade');
}
dataModel.filter({0: /^B.*/i, 1: mfilter});
},

// hide columns
hide : function(e){
colModel.setHidden(1, true);
}
};
}();

YAHOO.util.Event.on(window, 'load', EditorExample.init, EditorExample, true);
//YAHOO.util.Event.on(document, 'keypress', EditorExample.hide, EditorExample, true);
</script>
<div>
</div>
</body>
</html>

The error I get from the firefox error console is:

Error: this.element.dom has no properties
Source File: file:///C:/test/yui-ext.js
Line: 422

Which corresponds to a line containing this code (which I've split over a few lines so it doesn't do anything weird to the forum layout):


YAHOO.ext.grid.CellEditor=function(element){this.colIndex=null;
this.rowIndex=null;
this.grid=null;this.editing=false;
this.originalValue=null;this.element=getEl(element,true);
this.element.addClass('ygrid-editor');this.element.dom.tabIndex=1;
this.initialized=false;this.callback=null;};
YAHOO.ext.grid.CellEditor.prototype={init:
function(grid,bodyElement,callback){if(this.initialized)return;this.initialized=true;
this.callback=callback;this.grid=grid;
bodyElement.appendChild(this.element.dom);this.initEvents();},initEvents:function(){var stopOnEnter=function(e){if(e.browserEvent.keyCode==e.RETURN){this.stopEditing(true);}}

My guess is that I'm doing the script includes wrong, but I don't know what is missing or wrong.

I'm running this off of local dev, with the following file structure:

c:\test\ -- the root. I extracted all the YUI-ext stuff to here (maintaining folder hierarchy). So yui-ext.js is in here. I also downloaded your plants.xml sample and put it in here, and my index.htm page (shown above) is in here
c:\test\yui -- the YUI libraries

Does anyone know what that error means and how I can fix it?

Thanks for any help.

(Updated to add the actual includes that the forum software removed).

jack.slocum
5 Nov 2006, 1:26 PM
This is the line that is probably causing the error:

header: "Light",
width: 130,
editor: new yg.SelectEditor('light')

SelectEditor expects the id of an existing select field as the parameter and in your mark up I don't see one?

VKPS
5 Nov 2006, 2:01 PM
Doh! Obvious mistake. Thanks for that. I changed it to:


<div>
<select>
<option>Shade</option>
<option>Mostly Shady</option>
<option>Sun or Shade</option>
<option>Mostly Sunny</option>
<option>Sunny</option>
</select>
</div>

Unfortunately, I'm getting another error now:

Error: el has no properties
Source File: file:///C:/test/yui-ext.js
Line: 82

Which is this line here


this.insertHtml=
function(where,el,html){if(el.insertAdjacentHTML){
if(where=='beforeBegin'){el.insertAdjacentHTML(where,html);return el.previousSibling;}
else if(where=='afterBegin'){el.insertAdjacentHTML(where,html);return el.firstChild;}
else if(where=='beforeEnd'){el.insertAdjacentHTML(where,html);return el.lastChild;}
else if(where=='afterEnd'){el.insertAdjacentHTML(where,html);return el.nextSibling;}

I could be massively off but it looks like something might be calling an empty element to add HTML.

Any ideas/help? Thanks.

jack.slocum
5 Nov 2006, 2:40 PM
Does your container div tag have the id 'editor-grid'? Also, the container div must have a defined size and overflow:hidden is recommended.

By the way, if you check "Disable HTML in this post" it won't strip your tags.

VKPS
5 Nov 2006, 5:05 PM
Jack: Thanks a lot, that did the trick. I had stupidly (and accidentally) changed the id on the container to something else in one of the revisions.

anotine
8 Dec 2006, 1:57 AM
Thank you for the tip
All the update process is correct... I got my values correctly updated.

I think that there is a bug in the loadData. Even if i have a tag like : "<isEnabled>false</isEnabled>,
It set the value to true!!!. (BP in the formatBoolean associated

I have checked the document of jack:
http://www.jackslocum.com/blog/2006/09/10/adding-built-in-editing-support-to-the-yahoo-ui-extensions-grid/

and the "indoor" collumn is not correct according to the plant.xml!.

I will check
Thanks

anotine
8 Dec 2006, 2:06 AM
I think that The problem is that when CheckBox editor update a value, it set the valor to 'true' or 'false'.
The problem is that the default preprocesor i used (: Boolean) evaluate 'false' to true.
Boolean('false')=true.

tryanDLS
8 Dec 2006, 7:53 AM
There's another thread on this. If you copied the Boolean pre-processor/Render code from the example, there's a bug in how it passes the value.
http://www.yui-ext.com/forum/viewtopic.php?t=1147

anotine
8 Dec 2006, 8:09 AM
:oops: That is true,
Sorry