B
B
Bohdan Zhorov2019-04-30 13:38:36
JavaScript
Bohdan Zhorov, 2019-04-30 13:38:36

How to perform the operation once?

There is a form that is filled in a loop

<form>
                <div class="form-group" v-for="(item, index) in info">
                    <label>{{item.name}} <i class="fas"></i></label>
                    <input type="text" class="form-control" v-model="info[index].title"
                        @input="updateData($event, item)">
                </div>


                <button class="btn btn-success">Send Data</button>
            </form>

and the code that executes when data is entered
methods: {
                updateData(e, item) {
                    let i = 0
                    console.log()
                    if (!item.pattern.test(item.title)) {
                        e.target.classList.add('is-invalid')
                        e.target.classList.remove('is-valid')
                        e.target.previousElementSibling.lastElementChild.classList.add('fa-exclamation-circle')
                        e.target.previousElementSibling.lastElementChild.classList.remove('fa-check-circle')
                    } else {
                        e.target.classList.remove('is-invalid')
                        e.target.classList.add('is-valid')
                        e.target.previousElementSibling.lastElementChild.classList.remove('fa-exclamation-circle')
                        e.target.previousElementSibling.lastElementChild.classList.add('fa-check-circle')
                    }
                }
            }

I can’t implement the progress bar, how to track the validation operation only once, otherwise the progress is filled every time I enter a character. Thanks in advance!
PS In the code above, the progress is not filled now)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rodion Almetov, 2019-04-30
@radar4ick

https://ru.vuejs.org/v2/guide/syntax.html
won't v-once syntax work?

M
Mesuti, 2019-04-30
@Mesuti

I don't know if it will help. :)
You can do it through a condition.
For example, logically
i=1
If i=1, then... And i-1
will not run the second time, since i has changed after 1 iteration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question