can't set default value for a field in bubble
can't set default value for a field in bubble
mokozuki
Posts: 13Questions: 3Answers: 0
I am trying to prefill one of the fields (sort order field) with the highest number + 1 when a new record is added vi the bubble. i keep getting NaN, when i use the same expression in the js console, i do get the expected result. I have also tried with unary operator and Number() as well.
editor = new $.fn.dataTable.Editor({
ajax: '/ax/tableProductList.php?list_id='+$('#list-id').html(),
table: '#recordsTable',
fields: [
{ label: 'Order', name: "mz_product_list_items_bak.item_order", def: parseInt($('#recordsTable tr:last td:first-child').val() ,10)+1 },
{ label: 'ID', name: "mz_product_list_items_bak.product_list_item_id" },
{ label: 'Name', name: "mz_getProducts_dyfs.name_external" },
{ label: 'Item #', name: "mz_product_list_items_bak.product_id" },
{ label: 'Last Update', name: "mz_product_list_items_bak.last_update" },
{ label: 'Created By', name: "mz_product_list_items_bak.created_by" }
]
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Mokozuki,
I don't think you can do expressions there, I suspect it's expecting a constant. Could you just assigned that to a variable outside of the Editor initialisation and just refer to the variable there instead?
Cheers,
Colin
That line of code will evaluate, but it is attempting to get the
val()
from atd
cell, which isn't going to work (since a cell doesn't have a value property). Do you have aninput
inside that cell you want to get the value of, or do you just want the text value of the last cell in the table (cell().data()
)?Also you might want to use the
field.def
option as a function so it is evaluated when the "New" form is shown, rather than when the Editor is constructed.Allan
solved my problem. this how i implemented the suggestion:
setting last row number +1 as default value in bubble form when adding a new record