editor pre create function
editor pre create function
i need to create new row in table called service, and return the id of this row, and set the value of this row in other field in other table called CruisesService
this is my code:
editor.PreCreate += (sender, e) => {
object value;
e.Values.TryGetValue("Service.Service_Name_Heb", out value);
var id = CreateService(Enums.ServiceType.CruisesService, (string)value);
editor.Field("CruisesService.CruisesService_id").SetValue(id);
};
my question, is why precreate called even if there are error in validation?
what event i can used to make it happen clean without problem
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You could use "submitSuccess" and check whether the action was "create".
https://editor.datatables.net/reference/event/submitSuccess
hey, thank for replay, i want to make it on server side not client
https://editor.datatables.net/manual/php/events
just pick an event that suits you
i know which events have in server side, i pick the pre-create because it must done before new row created, but it seems to skip validtion
You seem to be using node.js. I didn't recognize that. At least for the PHP event I can tell you that it doesn't skip validation.
hey Allan, if you can look on the problem and have any idea how to solve this, it will be excellent for me
preCreate
is called before validation so validation can be added by that event handler! It's a good point, we should maybe have another event handler in between the two - postValidation or something...Allan
@allan
That's a big loophole in my validation! Please fix this asap.
I didn't understand the garbage in my database ... Now I do. Could you just pls change preCreate with a hotfix. No additional event needed in my opinion
I agree with @rf1234. It seems more logical to me that preCreate should be run against validated data.
hey Allan,do you have other way to solve the problem now? until there will be another event? or it will take couple of days to add new events?
I can't change when
preCreate
is triggered since folks depend on the current behaviour and it is documented that you can use it to assign values, which then need to be validated.But I will add a new event that will address this. It will be in Editor 1.9.3 which I expect to drop soon. I'll post back with the git commits so you can use it pre-release if you want.
Allan
Ok @allan , but I need a hot fix. How can I call all of the field validators and the global validator inside preCreate right now?
Since assigning values is done programatically the values should be valid anyway. For me validation only applies to user entries.
I assume preEdit has the same problem? Is that right?
@eyal_hb
I am checking my code right now - and found many problems because of the missing validation. I found one very special case where I really do validation INSIDE the preEdit event handler.
I can only provide a PHP example. So you would need to try to find this for node.js by yourself. The problem is: You need to sort of repeat the validation you have in your field instance validation already which for me is not feasible at all ...
Here we go - I've added
validatedCreate
andvalidatedEdit
:Thanks for the feedback on this!
Allan
good news! Thank you!
Just added those two lines to the Editor code and tested it with PHP. Works like a charm. Thanks for the hot fix, Allan!
Roland
hey Allan,thank you for the update,last question is how i implement this in net? i have dll of the DataTables-Editor-Server
Just a heads up. Should these
validatedCreate
andvalidatedEdit
maybe be documented here https://editor.datatables.net/manual/events and here https://editor.datatables.net/reference/event/ ? I only happened upon them with a google search and they are clearly useful!Those are the javascript events ... But validatedCreate and validatedEdit are server side and you can find the docs here (for PHP):
https://editor.datatables.net/manual/php/events
Thanks rf1234. Schoolboy error.