I have a propertygrid that starts with 3 rows. The third row should use a combobox to select a particular "validator", and when that selection occurs I want to fill out the rest of the propertygrid (rows 4 - x).
I have something kind of working, but at some point after selection it throws an error in the jQuery EasyUI library. The error occurs when getting a hidden text input and trying to access its panel property.
As best I can summarize, here is the code to build the widgets, followed by the "filler outer" function.
createEditForm : function (api, validatorIdx) {
$("#validatorDlg").remove();
var apiValidator = api.validators[validatorIdx];
var validator = getValidatorByName(vald.name);
// build propertygrid data structure with 3 initial rows
var rows = [
{ name : "HTTP Method", value : api.method, group : "API Settings", editor : null },
{ name : "API Path", value : api.uri, group : "API Settings", editor : null },
{name : "Name", value : apiValidator.name, group : "API Validator Settings",
editor : {
type : "combobox",
options : {
valueField : "name",
textField : "displayName",
data : MyScript.data.validators,
onSelect : function (record) {
$("#validatorForm").propertygrid("endEdit", 2);
}
}
}
}
];
var form = $("<table></table>", {id : "validatorForm", class : "easyui-propertygrid"});
var dialog = $("<div></div>", { id : "validatorDlg", class : "easyui-dialog" });
dialog.append(form);
dialog.dialog({
title : 'Validator Assignment to API',
width : 400, height : 400,
closed : false,
cache : false,
modal : true,
resizable : true
});
form.propertygrid({
showGroup : true,
data : {
rows : rows,
total : rows.length
},
onEndEdit : function (rowIndex, rowData, changes) {
if (rowIndex == 2 && !!changes.value) {
var validator = getValidatorByName(rowData.value);
if (!!validator) {
validatorSelected(api, validator);
}
}
}
});
}
...
validatorSelected : function (api, validator) {
var apiValidator = getApiValidatorByName(validator.name);
var form = $("#validatorForm");
var newData = form.propertygrid("getData");
// remove any existing validator fields (and display name)
newData.rows.splice(3);
// add back correct display name
var row = {
name : "Display Name",
value : validator.displayName,
group : "API Validator Settings",
editor : null
};
newData.rows.push(row);
// now add validator fields appropriate to this validator
for (var f = 0, field; (field = validator.fields[f++]) !== undefined;) {
row = {
name : field.name,
description : field.description,
value : null,
group : "Validator Fields",
editor : "text"
};
newData.rows.push(row);
}
newData.total = newData.rows.length;
form.propertygrid("loadData", newData);
return false;
}
Hopefully that is enough but not too much information. When I click the field in row 3, the combobox appears and lets me select a validator. Then the 4th and subsequent rows fill out as desired and an error is thrown.
What is the correct way to do this? Am I on the right track, or is there a better way? What is wrong?
Thanks.