Default value to a Datatable editor field, from a javascript function
Default value to a Datatable editor field, from a javascript function
Hello,
I want to pass a default value to a Datatable editor field, from a javascript function that generates a random code.
function makeid(length) {
var result = '';
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
I don't know how the function is referenced in the edit form field.
{
label: "code:",
name: "sml_maps.code",
default: ''
},
Thanks
This discussion has been closed.
Replies
You can use
fields.def
for that - see thename
field here: http://live.datatables.net/gadayoke/1/editColin
Thanks Colin for answering.
The "def" name field for the editor is clear. What I don't know is how I can pass a javascript makeid function.
fields.def
can be a function - see here: http://live.datatables.net/gadayoke/2/editThe only downside is that the length can't be passed in, so that will either need to be a constant or a value you pull from elsewhere.
Colin
In my case a constant is enough.
Thank you very much.