I've got a case when i need to provide a different source id based on if the user is editing or adding. My initial idea was to set a hidden field's value using the beforeShowForm hook, but it seems that the components get initialized before the hook's function is called. Thus I'm unable to determine what model is being created at that stage of initialization.
[A]
//initLoadNoEdit gets called... (At this point I need to know if its going to be an add/edit.)
initLoadNoEdit = function (elem) {
if ($('#curr_action').val() == 'add') {
createLoadNumberWidget(elem, "#Date", 'some_url');
} else {
createLoadNumberWidget(elem, "#modal_date", 'some_url');
}
}
var colModel = [
{ name: 'FI_ID', index: 'FI_ID', key: true, editable: false, hidden: true, search: false },
{ name: 'LILBP_ID', index: 'LILBP_ID', editrules: { required: true }, editoptions: { dataInit: initLoadNoEdit } }
];
//...before this gets called
var addBeforeShowOptions = function (form) {
$('#curr_action').val('add');
}
//...or this
var editBeforeShowOptions = function (form) {
$('#curr_action').val('edit');
}
I then tried to add an on click event on the button add/edit click of the grid, i tried .live(), .delegate(), and just a normal .click(). but had no results, the pager renders as follows..
[B]
<td id="pager_left" align="left">
<table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table navtable" style="float:left;table-layout:auto;">
<tbody>
<tr>
<td class="ui-pg-button ui-corner-all" title="Add new row" id="add_theGrid">
<div class="ui-pg-div">
<span class="ui-icon ui-icon-plus"></span>
</div>
</td>
</tr>
</tbody>
</table>
</td>
so i tried something like
$('#add_theGrid').live('click', function () { $('#curr_action').val('add'); });
//and
$('#pager_left').delegate('#add_theGrid','click', function () { $('#curr_action').val('add'); });
that being said... i don't think that passing a value into a variable is the best way to go about this, as I'm sure there should be a way of me to determine from the modal, what type of modal it is? I just haven't been able to find it yet..