1
selectize({
        valueField: 'Id',
        labelField: 'Name',
        searchField: 'Name',
        load: function (query, callback) {
            $.ajax({
                url: '/some_url/params?SOME_ID=4&keyword=' + encodeURIComponent(query),
                success: function (response) {}
            });
        }
    });

in the above snippet, is it possible to change the value of SOME_ID in request params based on some event
without destroying are re initializing the whole input ?
thanks in advance

the only solution i found was to destroy and re initialize the input, but am looking for a better approach

1 Answer 1

0

Try storing the value in a suitably scoped variable.

Since the load function is called for each search, it will be evaluated correctly.

For example

const selectizeQueryParams = {
  SOME_ID: 4, // initial value
};

document.addEventListener('some-event', (e) => {
  selectizeQueryParams.SOME_ID = 'newValue';
});

// ...

selectize({
  valueField: 'Id',
  labelField: 'Name',
  searchField: 'Name',
  load: function (keyword, callback) {
    $.get('/some_url/params', {
      ...selectizeQueryParams,
      keyword, // 👈 jQuery automatically encodes params when passed as an object
    }).done(function (response) {});
  },
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for this idea, it really saved me a headache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.