DT EDITOR: alternative for submit:changed? (submit:edited)

DT EDITOR: alternative for submit:changed? (submit:edited)

theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2
edited February 2017 in Free community support

I'm trying to minimize the data flow between server and browsers (sometimes request data gets cut because it's too long), so I've tried to use:

        formOptions: {
            main: {
                submit: 'changed'
            }
        },

I've noticed that this actually only sends changed fields, so if I select multiple fields and one of them is not changed (new value = old value), I won't get that key POSTed to server for data sets for which value remained unchanged. Would there be a way to still send the key that is missing, which would mean that we are submitting "edited" fields and not only "changed" fields?

Current (with submit:changed):

'data' => [
    1 => [
        'id' => 1
        'key' => 'value',
        'key2' => 'value2',
    ],
    2 => [
        'id' => 2                        <----missing "key" here
        'key2' => 'value2',
    ]
]

Wanted:

'data' => [
    1 => [
        'id' => 1
        'key' => 'value',
        'key2' => 'value2',
    ],
    2 => [
        'id' => 2
        'key' => 'value',        <-----also POST this one?
        'key2' => 'value2',
    ]
]

I would prefer that, so that I can always configure my validator based on first data set and then validate the whole data with it (I think should be sufficient for the way editor is designed - would always turn on the right validators).

Is there a mode or way around it and submit all "edited" fields, not only "changed" ones?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    It sounds like you might be describing the allIfChanged mode for form-options? With that it will submit all values if anything has changed.

    Allan

  • theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2
    edited February 2017

    Hey Allan,

    Thanks for quick reply. I forgot to mention that I also tried that option (found it mentioned on forum), but for some reason it's posting all of the fields with that, even if they weren't edited.

    I've tested it again today and I get the same. I'm doing a multi edit and I only change 1 field (other fields are set to "Multiple values" and weren't modified) but I still see all of the fields posted to server.

    Here is the part of the code that I changed/have there now:

            formOptions: {
                main: {
                    onReturn: 'none',
                    submit: 'allIfChanged'
                }
            },
    

    And a screenshot of the form, which looks normal (with 1 field changed as mentioned above): https://www.screencast.com/t/oAhduAQJ

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    but for some reason it's posting all of the fields with that, even if they weren't edited.

    I think I'm starting to get it now.

    So you only have a sub-set of the fields that could be edited actually being displayed. Are you using the API to control which fields are being shown or something?

    If I've understood correctly now, then I'm afraid that there is currently no option for doing exactly what you are looking for, although it is a nice suggestion. Thanks - I've added it to my list!

    Allan

  • theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2
    edited February 2017

    I think you got me wrong (although I was able to implement what you are describing by using editor.hide - dynamic editor fields, but that's not problematic).

    So again, I have all of the fields displayed in my case, but I only change value for one of them (others remain unchanged). When I then submit the data all of the fields get submitted, but I would only want that one field to be submitted (and it should always be there, even if it has the same value as before editing).

    Here is again screenshot of form that I submit (some fields are off page):
    https://www.screencast.com/t/oAhduAQJ

    And here is the request data that I get on server side:
    https://www.screencast.com/t/x66AXj6B0IsC

    I've tried with submit:'changed', but that doesn't fit my needs since it's removing keys for fields whose values hasn't changed (example in initial post).

    You've suggested that I should use submit: 'allIfChanged' (which sounds like it should do what I want), but for some reason I get the same result as if I was using editor without submit option (all fields get submitted, even for fields that were untouched in multiedit form).

    Should allIfChanged only submit type_id in this case, right? And each data array submitted should contain key with name "type_id"?

    Notice that I get all of the fields submitted, although I've only edited field with name="type_id".
    So the data posted to server side should look like this:

    'data' => [
        1 => [
            'id' => 1 (I append this one by making custom ajax call and looping through all fieldsets)
            'type_id' => '1',
        ],
        2 => [
            'id' => 2 (I append this one by making custom ajax call and looping through all fieldsets)
            'key' => '2',
        ],
    

    Btw, before posting here I've already updated DT Editor to the latest version (1.6.1).

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Oh oh - I see. Sorry - this is only an issue when multi-row editing?

    Allan

  • theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2
    edited February 2017

    I've just tested and the same happens when editing single row (that was for "allIfChanged" - which after reading the docs again seems to work fine - it is suposed to post all of the fields - if any changed).

    EDIT: Sorry, I think I now got you wrong with comment above. I think you were asking for "changed" and not "allIfChanged"? If so, the answer is yes. The problem only exists with multi row editing. Because if we are only editing one row, the case where one field value remained the same is not possible (because we are only editing 1 row, that would mean that value wasn't changed)...so I always get all changed fields/keys POSTed in that case.

    I think what I need is actually somewhere in between default option or allIfChanged (posts too many fields) and "changed" (minimizes the request data too much, by removing some keys in multi edit case), so I guess this functionality is not supported ATM? But I guess it shouldn't be hard to implement, since we should just skip removal of keys from request (the way that each data set POSTed has the same number of fields/keys)?

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Thanks for the clarifications. Yes you are correct. What you are looking for at the moment is not directly supported - it would, exactly as you say, require a modification in the code that builds the data to send to the server and is looking for changed values. I've added this to my list of future features - thanks for the feedback!

    Allan

  • theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2

    Np. Sorry for long texts, glad we came together. :)

    Thank you very much for that!

This discussion has been closed.