Data change before update
Data change before update
helpdesk
Posts: 20Questions: 3Answers: 0
Hi,
is there a chance so I can manipulate data before submitting, f ex. I have 1 field Date, second Day No which I'd like to calculate from some function. Or if someone choose value 1, I'd like to update DB with this value*$x.
Same for Table SELECT query, where can I edit it to add where clause
Thanks for your help!,
Jakub
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Is this using Editor? If so, then the
preSubmit
method can be used to modify the data submitted to the server.Allan
Hi Allan, thanks a lot for your help,
I managed to manipulate the data but don't know how to get a current row_id.
example:
editor.on('preSubmit', function (e, o, action) {
var area = editor.field('area');
o.data.row_22.area = "test"; // this will work - but i don;t know how to access current row_id
o.data.area = "test" ; // unfortunatelly doesnt as Im not accessing the right element.
});
Any suggestions? :) I'll be very grateful - Thanks Jakub
Hi Jakub,
You would need to use
$.each( o.data, function ( key, value ) { ... } );
wherekey
then the row id (row_22
in the above case). This is because of Editor multi row editing abilities.Thanks,
Allan
Thank you,
that solved my problem :)
Jakub
Hi Allan,
I'm facing a new problem now and can't find a solution :)
I need to make a few calculations before sending data to the server, I wanted to make it with ajax call but it returning with an error. Code below:
editor.on('preSubmit', function (e, o, action) {
Error that I'm receiving in the browser is:
Uncaught TypeError: Cannot read property 'id' of undefined
I'll be very grateful for any tips :)
Your only option to use Ajax there would be to disable the asynchronous aspect of Ajax which is very much not recommended.
Given that you are submitting data to the server and you need the server to do the calculation, why not just have the server do the calculation on the submitted data? That would save the additional complexity on the client-side.
Allan
Yeah, you're right,
I'm trying to do this way as I don't how to change this data on the server :) - where and how actually calculate all of them before query?
Th only method i know for changing data is presubmit suggested by you ;)
If you are using the Editor PHP or .NET libraries, then you could use the server-side events that were introduced in 1.5. I suspect that will be easier and ultimately more reliable.
Allan
Thanks for your help :)
It's working fine, but i believe I will need one more thing to finish my project, hope you will help again :)
I'm able to change values like this:
But don't know how to access data currently sent by the editor - example, I'd like to calculate week number regarding to the date sent in particular field in the editor 'my_date'.
So something like this,
Thx
Jakub
I use the editor.dependent() method. It gives access to the loaded and changed values in the data set. The advantage of this over the other event items is that the dependent fields, like you calculated week number, can be displayed on the form before submission.
But editor.dependent is a client side javascript, isn't it? I'm using php on the server side so the last necessary part is how to access data that should be submitted
Yes, editor.dependent is client side. When you tinker with stuff client side, by the time it gets to the server, the db doesn't know how the data was manipulated. As long as you are sending all the fields (AllIfChanged), your input field and any calculated fields will get to the db.
Now, you would be at the mercy of client side data integrity issues so that may not be an acceptable risk for your environment.
Back to your server side question, shouldn't you be able to get all the current (submitted) values with the $values array parameter of that preCreate function?
Hi thanks for a quick reply,
Indeed this could solve the problem but then I'll need to add week_no to the editor itself so it will be visible on adding / editing rows and I'd like to avoid that.
And yes $valules array has data that I need but I don't know how to address to get it.
Data Example:
Editor supports hidden fields.
http://editor.datatables.net/reference/field/hidden
Thank you very much! :)
I think now I'll be able to finally sort it out :)
J