Standalone edit doesn't clear field after save

Standalone edit doesn't clear field after save

mguinnessmguinness Posts: 34Questions: 8Answers: 0

When using Standalone model after clearing a field and submitting the data that field retains it's old value (isn't cleared).

This occurs since the JSON returned from the endpoint is serialized to ignore null values. I assume that the editor code only sets properties from the returned data which makes sense. However if the property is omitted from the returned data then the field retains it's old value.

I was able to workaround this by adding the following code to the edit event so that missing fields from the returned JSON are cleared. However it would be ideal if this could be incorporated into the editor library. Thoughts?

$.each(editor.fields(), function (idx, fld) {
    if (!data.hasOwnProperty(fld)) {
        var el = $('[data-editor-field="' + fld + '"]');
        if (el.filter('[data-editor-value]').length)
            el.attr('data-editor-value', '');

This question has an accepted answers - jump to answer


  • allanallan Posts: 49,501Questions: 1Answers: 7,286 Site admin
    Answer ✓


    You are correct - that is basically what is required and is actually intentionally put in like that. The reason being that Editor generally expects the server to return the full data set. If it doesn't, Editor can't know what the intention was (latest update time, empty the element, remove the element, etc) thus it is required to be explicit like you have done.


  • mguinnessmguinness Posts: 34Questions: 8Answers: 0

    Fair enough, but for my application I won't be returning the full data set. Another workaround is to use preEdit event which others might find useful. Thanks for your answer.

    .on('preEdit', function (e, json, data, id) {
        $.each(editor.fields(), function (idx, fld) {
            if (!data.hasOwnProperty(fld))
                data[fld] = null;
Sign In or Register to comment.