Encountering an issue with undefined ID when utilizing a radio input field in Vue JS

I'm facing an issue and I hope you can assist me with it.

My webpage contains Vue scripts and a list of radio selections rendered via Liquid tag and GraphQL results. The problem arises when I click the submit button or select a radio option, resulting in an error message in the console stating that a specific ID is undefined.

Interestingly, switching from radio buttons to checkboxes eliminates this problem:

I suspect the error lies within the ID handling but the console doesn't provide enough insight. Can you help identify where my mistake might be?

Below is the code snippet for the radio loop in my form:

<div class="cell large-6">
    <ul class="product_category_selections">
        {% graphql industry_list = 'get_homepage_industry_list' %}
        {% for industry_item in industry_list.items.results %}
            <li>
                <label>
                    <input type="radio" id="{{ industry_item.id }}" value="{{ industry_item.id }}" v-model="selected_industry" /> {{ industry_item.properties.name }}
                </label>
            </li>
        {% endfor %}
        <input type="text" v-model="selected_industry" name="form[properties_attributes][industry]" />
    </ul>
</div>

Followed by the scripting section:

new Vue({
    el: '#request-sample-form-app',
    delimiters: ["!!", "!!"],
    data: {
        selected_industry: [],
        first_name: '',
        last_name: '',
        contact_number: '',
        email: '',
        company_name: '',
        address_1: '',
        address_2: '',
        city: '',
        state_province: '',
        zip_postal_code: '',
        country: '',
        application_description: ''
    },
    methods: {
        initApp: function() {
            console.log('App initialized!');
            this.country = 'Australia';
        },
        validateRequestSampleForm: function() {

            var error = "";

            if (!this.selected_industry) {
                error += '<p>Please choose an industry</p>';
            }

            if (!this.first_name) {
                error += '<p>Please enter first name</p>';
            }

            // SOME ERROR VALIDATIONS ...
            if (error) {
                Swal.fire({
                    type: "error",
                    title: "Error",
                    html: error
                })
                return;
            } else {
                return true;
            }

        },

        validateForm: function() {
            event.preventDefault();
            $("#request_sample_form_application").submit(); 
        }
    },
    mounted() {
        this.initApp();
    }
});

Answer №1

Discovered the root cause of the issue,

Initially attempted to utilize the onchange event method, but the problem persisted. Upon inspecting the radio tag, it was apparent that the name attribute was missing.

Upon inserting the name attribute, the problem was finally resolved. It's puzzling how such a simple attribute like name could disrupt the script.

 <div class="cell large-6">
                    <ul class="product_category_selections">
                        {% graphql industry_list = 'get_homepage_industry_list' %}
                        {% for industry_item in industry_list.items.results %}
                            <li>
                                <label>
                                    <input type="radio" name="selected_industry_name" id="{{ industry_item.id }}" value="{{ industry_item.id }}" v-model="selected_industry" /> {{ industry_item.properties.name }}
                                </label>
                            </li>
                        {% endfor %}
                        <input type="text" v-model="selected_industry" name="form[properties_attributes][industry]" />
                    </ul>
                </div>

screenshot:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using JQuery validate to extract the interest rate from a regular expression

I am looking for a regular expression that can extract the interest rate. I need it to accept values such as: Examples: 0 0.4 0.44 4 44 4.00 44.00 4.2 4.22 44.22 Minimum value allowed is 0 and maximum is 99.99 The regular expression should be ab ...

Determine how the scale of a transform changes over time by calculating the function of elapsed time [ transform: scale(x, y

I am currently working on a container that can be expanded and collapsed simply by clicking on a chevron icon. The functionality to collapse or expand the container resides within a function called transformAnimation. This function code closely resembles t ...

How can I resolve the issue of not returning anything ondrop in my code?

Whenever I drop my div containing an image, I don't see anything. And when I try to access its ID, I get a null value. How can I extract information from a div with an image and append a row with it? For code samples or to check the codepen example, v ...

Create a unique photo gallery layout using Vue.js with a personalized overlay feature

Is there a way to create a photo grid where each image acts as a card with a custom overlay that displays details when hovered over? I attempted to achieve this using "Beautify" and "Bootstrap-Vue" without success. An example of the functionality I am try ...

Why is it that Angular is unable to locate the component factory for my component, even though I have declared it in the entryComponents option of my Module?

Is there a way to dynamically create and show a component in an ngx-bootstrap's modal? I attempted to declare the component in the entryComponents option of RegMktRiskHomeModule, but it did not work. Currently, I am only able to declare the Scenarios ...

What is the process for placing a breakpoint within a "require"-d library using node inspector?

As I navigate through a library that is multiple layers deep from my project, I am facing the challenge of setting a breakpoint inside it. Node-inspector is a new tool for me, and I am currently exploring how to access the library and set breakpoints in i ...

Ignoring page redirects in Node.JS

Directories are organized as follows: -public -landing -landing.html -Login -login.html -register -register.html -routes HTMLroutes APIroutes - server.js All commented code are attempts I have made without success if (bcry ...

Guide to accessing object items in v-for in VueJs

Upon inspection, the following results are being displayed: In the Vue template code provided: <select class="form-select" v-model="post_format.wpml_language"> <option v-for="(lang, index) in wpml_languages" :value="lang">{{lang}} {{index}} ...

The issue with Array.prototype.join in Internet Explorer 8

In my current working scenario, I encountered an issue with the following code snippet. It performs well in the latest versions of Internet Explorer (IE), but the join function fails to work correctly in IE 8 Version. <!DOCTYPE html> <html xmlns= ...

Tips for keeping a checkbox checked on page refresh in React JS

I am facing an issue where the checkbox, which was checked by the user and saved in local storage, is displaying as unchecked after a page refresh. Even though the data is stored in local storage, the checkbox state does not persist. The code I am using i ...

Angular ngClick on a rectangle within an SVG element

Need to trigger angular click functions on rects in an svg. <rect data-ng-click="scrollToAnchor('siteHeader')" fill="#010101" width="501" height="81"></rect> Here's the function: $scope.scrollToAnchor = function(anchor) { $a ...

What could be causing my tab code to not function flawlessly?

I am attempting to implement a tab concept on my website. For example, the tab names are Monday...Tue.. up to Sunday. Each tab contains an image file based on the days (size 460*620). When I run my page, it shows all images, but what I need is for the imag ...

Manipulate Images Efficiently with jQuery

Are there any jQuery plugins or JavaScript controls available that can display an array of images, with the option to delete an image based on user action? For example, something similar to this: , but with a dedicated delete button on each image. One ad ...

Tips for declaring the project npm registry within the package.json configuration file

Currently, I am juggling multiple projects simultaneously and facing the issue of each project having a different node module registry. For instance, project A sources its modules from http://registroy.foo.com, while project B pulls modules from http://re ...

Strategies to manage or prevent a timezone offset while deploying a Next.js application on Vercel

Is there a way to ensure that a React/Next.js App always displays the local time in CEST, regardless of the user's location? For example, if I receive GMT time from the backend and want to offset it to display the CEST timezone, how can I achieve this ...

Troubleshooting: Issues with Custom Image Loader in Next.js Export

I'm encountering a problem while attempting to build and export my Next.JS project. The issue lies with Image Optimization error during the export process. To address this, I have developed a custom loader by creating a file /services/imageLoader.js ...

Top ways to avoid default on anchor tags: best practices for preventing this issue

Previously, excluding the criticism for not using unobtrusive JS, I typically employed anchors with inline onclick attributes for AJAX loading in the following format: <a href="http://example.com/some/specific/link.php?hello=mum" class="menu" id="m ...

When initially compiling Angular 5, an error (TS2339) may occur, but after a successful compilation, everything runs smoothly

In a unique scenario, I wrote code that fetches information from an API server without knowing the structure of the response fields. Once I receive the response, I need to create a form for updating the data and sending it back. To handle unknown ngModel p ...

What is the reason for IE displaying null when the model does not exist?

Why does IE 11 render 'null' if my model does not exist? For instance: <tr> <td [innerHTML]="model?.prop1 | my-pipe"></td> </tr> Imagine this scenario: When the page loads, a request is sent to the server and the res ...

What are the methods for altering the material of a glTF model using THREE.js?

I've created a model using Blender and baked all the lighting and textures. However, when I import it into THREE.js in .glb format, it automatically uses the standard material. While this may work in certain cases, my concern is that I want to retain ...