How to clear select menu before update
How to clear select menu before update
Cryptograph
Posts: 3Questions: 1Answers: 0
Hello, I'm using refresh button for datatable editor like below codes
{
text: '<span class="fa fa-refresh"></span>',
editor: editor,
action: function ( e, dt, node, config ) {
dt.ajax.reload();
$.getJSON('ajaxurl.php', function (data) {
$.each(data, function (index, element) {
categories_select_menu.push({
value: element.id,
label: element.kategori_ismi
});
//console.log(element.kategori_ismi);
});
editor.field( 'ust_kategori' ).val(''); //Not Working
editor.field( 'ust_kategori' ).update( categories_select_menu );
});
}
}
I update select menu options this command "editor.field( 'ust_kategori' ).update( categories_select_menu );" but options are repeating. How can I clear select menu options before update command
This discussion has been closed.
Answers
Hi @Cryptograph ,
You can use the
clear()
call - so replacewith
Cheers,
Colin
I try clear() function but not working. I get an error when I use clear()
TypeError: editor.field(...).clear is not a function
Sorry, reading the pages here myself. Instead of the
update()
, could you just set the value, which would erase the old value, withfield().val()
orfield().set()
?I noticed the problem. The problem does not arise from these commands "field.value() or field.set() or field.update()".
I have defined before the categories_select_menu array variable. The same values were repeated because each refresh operation added to the end of the array variable.
I solved the problem by redefining the categories_select_menu array variable