Datatables Editor: custom field type question

Datatables Editor: custom field type question

marcelvmarcelv Posts: 27Questions: 6Answers: 0
edited June 2015 in Editor

Hi,

I have created a custom field type (like here: https://editor.datatables.net/examples/plug-ins/fieldPlugin.html) but now I want to manipulate the data returned from this field.

I see the get function returns the value which is used for further processing, but for example if I ask peoples age, I want to return data like this to the server:
data['age'] = 10 > this is the input field value entered by the user
data['ischild'] = no > this value I determine within my plugin and I want to post this to the server also.

Now I got this working by manipulating data within the preSubmit event, but I'd rather put this logic within my plugin code since I have got multiple scenario's like this. Of course you would say: why not determine this 'ischild' value server side? That's because I have no control of the server side script, it`s external and I just post data and they process it.

So basically my question is can I add extra data from my plugin to be returned as post data to the server side script.

If it`s not possible I will just keep 'hacking' inside the preSubmit event to add extra data and post it, but it would be much nicer from coding perspective to be able to do this within my plugin.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    A field can only really have a single value. It is not possible for a single field to submit two different parameters (i.e. the ischild and age parameters you have).

    Having said that, a field value return an object as a value, so you could feasibly use:

    return {
      age: 10,
      ischild: 'no'
    };
    

    But you would need to update your server-side script to accept such data. The pre-build libraries will not automatically process such data, you would need to use custom set formatters.

    Allan

  • marcelvmarcelv Posts: 27Questions: 6Answers: 0

    Thanks!

This discussion has been closed.