Set value to 0 when autoComplete field is empty/deleted

Set value to 0 when autoComplete field is empty/deleted

klinglerklingler Posts: 90Questions: 42Answers: 2
edited May 2022 in Editor

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

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    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

  • klinglerklingler Posts: 90Questions: 42Answers: 2

    Hello Allan

    I just leave it with checking in the backend if an empty string was submitted....

Sign In or Register to comment.