Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Set id of Added Element #1327

@LuigiMdg

Description

@LuigiMdg

Hi,
when I add an element, I send an AJAX request that return to me the id for the element..
I'm trying to set this id to the value of the element, but this code not work..
You can help me?

	$('#colori').selectize({
		plugins: ['remove_button'],
		maxItems: null,
		valueField: 'id',
		labelField: 'title',
		searchField: 'title',
		sortField: 'title',
		options: options,
		create: true,
		onOptionAdd(colore){
			var risposta = confirm("Aggiungere Colore?");
			if(risposta == 1){
				$.ajax({
					type: "POST",
					url: "static/aggiungiColore.php",
					data: "colore="+colore,
					dataType: "html",
					success: function(idColore){
						$("#colori option[value='"+colore+"']").remove();
						$("#colori").append('<option value="'+idColore+'">'+colore+'</option>');
						$("div[data-value='" + colore + "']").remove();
						$(".selectize-input").append("<div class='item' data-value='"+idColore+"'>"+colore+"<a href='javascript:void(0)' class='remove' tabindex='-1' title='Remove'>×</a></div>");
					},
					error: function(){
						alert("Errore!");
					}
				})
			}
		},
		onItemAdd(){
		//rimuovo il required dall'input text dei colori
		$("#colori-selectized").removeAttr('required', true);
	}
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions