Recover field value in Editor
Recover field value in Editor

Hello
How can I recover the value of NFAC in editor ?
fields: [
{label: 'ID:', name: "invoice.id", type: "hidden"},
{label: 'NFAC:', name: "invoice.nbi", type: "hidden", def: function (data) {return invoice.id + "L"; } }
]
This question has accepted answers - jump to:
This discussion has been closed.
Answers
https://editor.datatables.net/reference/api/field().label()
in case you mean the value of the label "NFAC"
https://editor.datatables.net/reference/api/field().val()
in case you mean the value of the field
https://editor.datatables.net/reference/api/field().name()
in case you mean the name of the field
... and many more ... just use the search field in the upper right corner.
In fact at the time of creation I would like to recover the invoice.id value to inject it
into the second field ( invoice.nbi) but I can't do it !
How can i get the invoice.id value ?
Did you check the Editor event list?
https://editor.datatables.net/manual/events
Of course you can also use the "preSubmit" event but then you don't have the form fields available any longer which is a clear disadvantage.
Thank you rf1234, the method is good but does not work with me because I think the id is generated by MySQL (AUTO INCREMENT), I do not know if there is a solution!
But then it is something you need to resolve server side! Nothing you can do @ the front end.
Sounds like you want to establish a foreign key relationship. I would take a look at the Editor join examples that do not use a link table.
Otherwise please post a test case as per the forum rules.
Actually i was thinking of creating an invoice number field and giving it a special shape based on the unique id number.
example:
invoice.id = 1 --> invoice.nbi = IN20-0001
invoice.id = 2 --> invoice.nbi = IN20-0002
invoice.id = 33 --> invoice.nbi = IN20-0033
...
Ok, you can only do that server side in your case because you need to get the last insert id from MySQL first. Take a look at the respective server side events for PHP, .NET or whatever you are using. What is your server side language?
PHP
Question is: Why would you save this if there is a clear rule how to generate this field's value based on the id? So if you would like to show it in your data table as well it would be easiest to retrieve it from the server.
a) you don't save the field but just retrieve it as an alias of the id field.
b) you save the field by updating your table row based on the last insert id (if your nbi field has NULL as the default in MySQL):
https://editor.datatables.net/reference/event/postCreate
rf1234 you for your help and your kindness
.
The ALIAS method is interesting, but I give up, and I keep the client side method without registration.
ok - I personally like the alias method a lot: Easy and no hassle client side. But that is probably a question of taste. Good luck!
Thank you very much again, your method works perfectly