Selectize plug-in, multiple value, deselect all does not sent null to backend

Selectize plug-in, multiple value, deselect all does not sent null to backend

hapihapi Posts: 18Questions: 3Answers: 0

We are using Selectize plug-in and it works normally very well. However when using it with multi values we have a problem in case the user decides later to remove all values. If nothing is selected, the editor POST does not post null for this field but rather skips it. In consequence the editor backend is not changing the value from something to null. How can I force the plugin to post a value on edit back to the server even nothing was selected?

Cases:
- Change from nothing (null) to something OK
- Change from something to something else OK
- Change from something to nothing (null), NOK, no change finally in the DB as this value is not posted to the server

I have implemented a check in pre-edit of the backend, if not posted, set to null. But if we are using inline Editing, anyway the full form is not sent and then my check removes the values.

Maybe this can be fixed on pre-submit of the editor, but how can I force him to consider this field, even if it is empty?

Many thanks in advance.

 slectize_opts = {
        plugins: ['remove_button','restore_on_backspace'],
        delimiter: '|',
        maxItems: 100,
        persist: false,
        valueField: 'VALUE',
        labelField: 'LABEL',
        searchField: 'LABEL',
        create: true,
        render: {
            option: function(item, escape) {
            ...
            }
        },

        load: function(query, callback) {
        ...
        }
    };



"fields": [
      ...
      ,{
        label: ...
        type:  "selectize",
        opts: slectize_opts_RELATED_ID
       }

Replies

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Are you able to give me a link to the page in question please? Typically we post a -many-count parameter to the server along with the array of selected values. That is how our server-side libraries determine if there are no values or if there was simply no edit on that field.

    That said, you are using the a delimiter option for Selectize, so I would have expected Selectize to just submit an empty string at this point.

    If you have a link to the page I'll trace it through.

    Thanks,
    Allan

  • hapihapi Posts: 18Questions: 3Answers: 0

    Hi, unfortunately I can't give you access. I checked

        editorEDIT.on('preSubmit', function ( e, data, action ) {
            console.log(data);
        } );
    

    here the filed is correctly set as data.row_123.CAL_DATA.MYSELECTIZE_FIELD: [] (empty array). In the POST after it is missing.

    Do I have the possibility here, to advice the editor to send the field? I could check the length and if 0 I could do something.

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Can you show me a screenshot of the data being set to the server perhaps?

    Thanks,
    Allan

Sign In or Register to comment.