Set value to 0 when autoComplete field is empty/deleted
Set value to 0 when autoComplete field is empty/deleted
Good afternoon (o;
I use several autoComplete fields in the editor to choose different categories a product can be in...all fine when editing...
Now when i want to remove a specific category with deleting the input field....
how can I send a value of 0 when the field is emptied?
The part looks like:
{
label: "Category 2",
name: "category2",
type: "autoComplete",
opts: {
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
editor.val('cat2', ui.item.value);
}
},
},
{
label: "cat2",
name: "cat2",
type: "hidden"
},
Well I could check for "category2 being an empty string in the backend:
$cat2 = $post['category2'] ? $post['cat2'] : 0;
Answers
I'm not sure what you mean by emptied in this context - does your jQuery UI AutoComplete control have a clear button? If so, you'd need to hook into that to set its value to zero (or perhaps an empty string and then use
preSubmit
to check for an empty string and modify it to be 0.Allan
Hello Allan
I just leave it with checking in the backend if an empty string was submitted....