Extra field to control another one via dependent() always being sent to server

Extra field to control another one via dependent() always being sent to server

bestoffbestoff Posts: 3Questions: 2Answers: 0

Hi, I'm using Editor and I have the necessity to add a checkbox that controls the value of an upload field. Here's the behaviour I'm trying to get:
I have an upload field for an image and I want to 'store' if that upload is necessary or not. So I added this field to my editor

{
        label: '',
        name: 'noimg',
        type: "checkbox",
        options: [
            { label: 'No image required', value: 1 }
        ],
        separator: '',
        unselectedValue: 0
}

And through dependent():

editor.dependent('noimg', function (val, data, callback) {
        if (val == 1) {
            editor.field('prodotti.immagine').set(0);
            editor.hide('prodotti.immagine');
        } else {
            if (editor.field('prodotti.immagine').val() == 0) {
                editor.field('prodotti.immagine').set('');
            }
            editor.show('prodotti.immagine');
        }
        callback(true);
    });

I show/hide and set value for the upload field, based on the checkbox status.
The editor is set to 'changed' to submit only changed fields. However, since I added noimg field, every edit ends with noimg data being submitted with 0 value.
Is there an option to prevent a field from being sent to the server? Or am I using the wrong approach to obtain this?
Thank you!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Is there an option to prevent a field from being sent to the server?

    Yes, the fields.submit option can be set to false to stop it being sent.

    Allan

  • bestoffbestoff Posts: 3Questions: 2Answers: 0

    As simple as that! I'm sorry I totally missed that, thank you :)

Sign In or Register to comment.