Setting defaults at runtime
Setting defaults at runtime
Hi Allan
I'm having trouble setting a default value for a field I'm creating at runtime in Editor.
If I create the field when the editor instance is originally created there is no problem as below:
"fields": [
{
"label": "Id",
"name": "id",
"type": "hidden"
},
{
"label": "Code",
"name": "code",
"type": "text",
"default":"hello!"
}
]
If I create the field using one of the "events" methods the field is created and perfectly usable it just will not register a default, as below code example.
$(document).ready(function() {
var CodeEditor = new $.fn.dataTable.Editor( {
"ajaxUrl": "include/table.Codes.php",
"domTable": "#Codes",
"events": {
"onPreSubmit":function(){
CodeEditor.add(
{
"label": "eType",
"name": "eType",
"type": "text",
"default": "hello!"
}
)
}
},
Am I missing something obvious here or is what I'm trying to do not feasible?
Thanks
Ivan
I'm having trouble setting a default value for a field I'm creating at runtime in Editor.
If I create the field when the editor instance is originally created there is no problem as below:
"fields": [
{
"label": "Id",
"name": "id",
"type": "hidden"
},
{
"label": "Code",
"name": "code",
"type": "text",
"default":"hello!"
}
]
If I create the field using one of the "events" methods the field is created and perfectly usable it just will not register a default, as below code example.
$(document).ready(function() {
var CodeEditor = new $.fn.dataTable.Editor( {
"ajaxUrl": "include/table.Codes.php",
"domTable": "#Codes",
"events": {
"onPreSubmit":function(){
CodeEditor.add(
{
"label": "eType",
"name": "eType",
"type": "text",
"default": "hello!"
}
)
}
},
Am I missing something obvious here or is what I'm trying to do not feasible?
Thanks
Ivan
This discussion has been closed.
Replies
In theory yes, you can add new fields to an Editor instance at almost any time using the add API method as you have done - however, as you have seen it actually won't work fully in onPreSubmit (and a good number of the other callbacks) because the default values for the fields are set when the Editor edit display is shwon (i.e. whent he lightbox is brought up in the browser window). This has occured before you add the field, thus you get the problem you are seeing.
Are you simply looking to add an extra field to submit to the server dynamically? If so, you can just use something like:
[code]
onPreSubmit: function (submitData) {
submitData.data.myParameter = myValue;
}
[/code]
Regards,
Allan
Cheers
Allan