0

I have a set of email fields. When I start typing in one, it gives me suggestions. Then I select a suggestion, and it gets set for ALL email fields. Is there a way to select email suggestions for just one email field even though there might be several on the page?

It's a vue.js application. Here is the template for the email field:

                <v-layout row wrap v-for="(item, index) in prop.roles" :key="index">
                    <v-flex mb-4>
                        <div class="ath-container">
                            <div class="ath-controls-container mb-2">
                                <v-text-field
                                    :id="'email-' + index"
                                    class="d-inline-block ath-email-field"
                                    outline
                                    label="Email"
                                    v-model="item.email"
                                    placeholder="username@example.com"
                                    :rules="[v => !!v || 'Email is required',
                                        v => /.+@.+/.test(v) || 'Email is invalid' ]"
                                    maxlength="255"
                                    required>
...
            </div>
        </div>
    </v-flex>
</v-layout>

There is an "add" button that allows the user to add more email fields. But I would like them each treated independently when selecting suggested emails from the popup list. Thanks.

EDIT: data and method blocks requested.

    data() {
        return {
            isValid: false,
            isCompany: false,
            prop: {
                companyName: null,
                hasAdditionalTitleHolders: null,
                roles: [{
                    email: null,
                    notifying: false
                }],
                isMarried: null,
                hasSpouse: null
            },
            dowerRightsFilenameData: null,
            rafId: 0, // request animation frame ID (see animateStatusBarIfInView() below)
            notifyingAll: false
        }
    }
methods: {
        onDowerRightsFormPicked(e) {
            this.dowerRightsFilenameData = e.target.files[0].name;
            this.$emit('dower-rights-form-picked', e);
        },

        deleteDowerRightsForm() {
            this.dowerRightsFilenameData = '';
            this.$emit('delete-dower-rights-form');
        },

        animateStatusBarIfInView() {
            for (let index = 0; index < this.prop.roles.length; index++) {
                if (this.$refs['ath-status-bar-' + index] && this.$refs['ath-status-bar-' + index][0]) {
                    const athStatusBar = this.$refs['ath-status-bar-' + index][0];
                    const ath = this.prop.roles[index];
                    if (this.isInViewport(athStatusBar)) {
                        let className = 'ath-status-bar-init';
                        if (ath.acceptedAt) {
                            className = 'ath-status-bar-accepted';
                        } else if (ath.verifiedAt) {
                            className = 'ath-status-bar-verified';
                        } else if (ath.accountCreatedAt) {
                            className = 'ath-status-bar-account-created';
                        } else if (ath.invitedAt) {
                            className = 'ath-status-bar-invited';
                        }
                        athStatusBar.classList.add(className);
                    }
                }
            }

            // repeat:
            if (this.rafId) window.cancelAnimationFrame(this.rafId);
            this.rafId = window.requestAnimationFrame(this.animateStatusBarIfInView);
        },

        isInViewport(element) {
            const rec = element.getBoundingClientRect();
            return rec.top < (window.innerHeight || document.documentElement.clientHeight) && rec.bottom > 0;
        },

        notifyAllAths() {
            this.notifyingAll = true;
            let index = 0;
            const allIndexes = this.prop.roles.map(ath => index++);
            this.$emit('notify-aths', allIndexes);
        }
    }
gib65
  • 1,709
  • 3
  • 24
  • 58
  • 1
    Please at least add the `data` and `methods` blocks. – Yom T. Jun 21 '20 at 05:26
  • Done (tho I don't see how it helps). – gib65 Jun 21 '20 at 21:09
  • 1
    In your `` element, where do `item` and `index` come from? Presumably there's a `v-for` somewhere that you've omitted for some reason – Phil Jun 21 '20 at 23:40
  • Sorry, I thought it would be obvious from my description that there are many email fields. I added the v-for. – gib65 Jun 22 '20 at 04:44
  • So you're talking about the browser's auto-fill feature, correct? I'm assuming you don't want to just disable it all-together. I'd say it's probably filling in all the fields by assuming they're like _"Email"_ and _"Confirm email"_. Similar to [this question](https://stackoverflow.com/questions/26848754/chrome-autocomplete-multiple-email-fields) but unfortunately there's no answer – Phil Jun 22 '20 at 06:34
  • That's too bad. Thanks anyway. – gib65 Jun 23 '20 at 04:17

0 Answers0