New options

The jSuites.dropdown and autocomplete plugin allows the user to add new options to the dropdown. This feature is disabled by default. The initialization flag newOptions: true will enabled the feature. There is an extra option to handle ids generate in a remote server, as follow:

<html>
<script src="https://bossanova.uk/jsuites/v3/jsuites.js"></script>
<link rel="stylesheet" href="https://bossanova.uk/jsuites/v3/jsuites.css" type="text/css" />

<div id="dropdown"></div>

<script>
jSuites.dropdown(document.getElementById('dropdown'), {
    data:[
        { id:'1', 'Tomatoes' },
        { id:'2', 'Carrots' },
        { id:'3', 'Onions' },
        { id:'4', 'Garlic' },
    ],
    newOptions: true,
    oninsert: function(o, item, dataItem) {
        jSuites.ajax({
            url: '/jsuites/getId',
            type: 'POST',
            dataType: 'json',
            data: { data: item },
            success: function(result) {
                // Set the item id from the number sent by the remote server
                item.value = result;
                // Set the new value for the data
                data.value = result;
            }
        });
    },
    width:'280px',
});
</script>
</html>