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
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
Yes, the
fields.submit
option can be set tofalse
to stop it being sent.Allan
As simple as that! I'm sorry I totally missed that, thank you