looping elements without a wrapper element in vuejs - vue.js

I have the following code which I would like to generate through a v-for:
<div class="rating-container">
<input type="radio" name="star" value="5" id="star-5">
<label class="star-radio" for="star-5">5</label>
<input type="radio" name="star" value="4" id="star-4">
<label class="star-radio" for="star-4">4</label>
<input type="radio" name="star" value="3" id="star-3">
<label class="star-radio" for="star-3">3</label>
<input type="radio" name="star" value="2" id="star-2">
<label class="star-radio" for="star-2">2</label>
<input type="radio" name="star" value="1" id="star-1">
<label class="star-radio" for="star-1">1</label>
</div>
But I need to keep them in the same order, I mean, a label right after the radio input element, I know v-for on the input tag or the label element would generate all the inputs first and then all the labels
Is there any way to do this with vuejs v-for so that I can preserve the element order and generate them with a loop ?

You could use the template tag as
The template element holds HTML code without displaying it
<div id="app">
<div class="rating-container" >
<template v-for="n in 5">
<input type="radio" name="star" :value="n" :id="'star-'+ n">
<label class="star-radio" :for="'star-'+ n">{{n}}</label>
</template>
</template>
</div>
If you want to loop trough the items in a reversed way you have to do it yourself

Related

Radiobutton values are not passing to Controller

In my View I am using following radio buttons
<div class="row">
<div class="col-md-4">
<input name="type" asp-for="loremType" value="1" type="radio" /><label for="rdbLetters">Letters</label>
</div>
<div class="col-md-4">
<input name="type" asp-for="loremType" value="2" type="radio" /><label for="rdbWords">Words</label>
</div>
<div class="col-md-4">
<input name="type" asp-for="loremType" value="3" checked="checked" type="radio" /><label for="rdbParagraphs">Paragraphs</label>
</div>
</div>
loremType is the parameter from the Model Class. Even though the value set as 1,2,3 these values are not passed to the controller.
Am I doing something wrong?

Vuejs checkbox disable if checked

I have 4 checkbox inputs and i want to disable each input if is checked!
And disable all inputs if user checked 2 checkboxes i achive this with v-model length >= 4
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" value="1" v-model="inputs" disabled="inputs.length >= 4">
text1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" value="2" v-model="inputs" disabled="inputs.length >= 4">
text1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" value="3" v-model="inputs" disabled="inputs.length >= 4">
text1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" value="4" v-model="inputs" disabled="inputs.length >= 4">
text1
</label>
</div>
What can i do to disable the input checkbox user checked?
Thanks for your question posting.
I think the disabled property of input tags should be :disabled.
<input type="checkbox" value="1" v-model="inputs" :disabled="inputs.length >= 4" />
Hope for your best result.
Thank you.

How to render form on button clic in Vue?

I have two registration forms ona a page, but I only want to render one by clicking on proper button: 'Contract Form' or 'Company Form'. Should I do it with v-if? In the code below I just copied few lines of the form.
<template>
<div>
<button #click="contract">UMOWA</button>
<button #click="company">FIRMA</button>
<div v-if="contract">
<form method="post" #submit.prevent="onSubmit">
<label for="firstname">IMIĘ</label>
<input id="firstname" v-model="firstName" type="text" required />
<label for="lastname">NAZWISKO</label>
<input id="lastname" v-model="lastName" type="text" required />
<button type="submit">Zarejestruj się</button>
</form>
</div>
<div v-if="company">
<form method="post" #submit.prevent="onSubmit">
<label for="firstname">IMIĘ</label>
<input id="firstname" v-model="firstName" type="text" required />
<label for="lastname">NAZWISKO</label>
<button type="submit">Zarejestruj się</button>
<input id="lastname" v-model="lastName" type="text" required />
<label for="email">ADRES E-MAIL</label>
<input id="email" v-model="email" type="text" required />
<button type="submit">Zarejestruj się</button>
</form>
</div>
</div>
</template>
Yes but you will need to add true in the buttons onclick:
<button #click="contract = true">UMOWA</button>
<button #click="company = true">FIRMA</button>

Selenium Java select div based on nested element text

I have below HTML structure. Would like to select the label which has with value 3.x
I have tried below xpath expressions
"//label[contains(#class='options')]/div/p[contains(text(),'3.x')]"
"//div[#class='answerOpts']/label[contains(#class='options')]/div/p[contains(text(),'3.x')]"
But it didn't work. Received Exception org.openqa.selenium.NoSuchElementException: Unable to locate element:. Could you please let me know the solution?
HTML structure
<div class="answerOpts">
<input class="optionRadios" type="radio" name="2565" id="answer_9218" value="9218">
<label class="options searchable" for="answer_9218">
<div>
<p>2.x</p>
</div>
</label>
<input class="optionRadios" type="radio" name="2565" id="answer_9219" value="9219">
<label class="options searchable" for="answer_9219">
<div>
<p>3.x</p>
</div>
</label>
<input class="optionRadios" type="radio" name="2565" id="answer_9220" value="9220">
<label class="options searchable" for="answer_9220">
<div>
<p>4.x</p>
</div>
</label>
<input class="optionRadios" type="radio" name="2565" id="answer_9217" value="9217">
<label class="options searchable" for="answer_9217">
<div>
<p>1.x</p>
</div>
</label>
</div>
Here some xpath examples how you can get label element:
//label[normalize-space(.)='3.x']
//label[contains(#class,'options') and .//p[.='3.x']]
//label[contains(#class,'options') and #for and .//p[.='3.x']]
//p[.='3.x']/ancestor::label[1]
//p[.='3.x']/ancestor::label[contains(#class,'searchable')][1]
try with below xpath
.//div/p[text()='3.x']/parent::div/parent::label/preceding-sibling::input[1]

Unable to click on <label> to select a radio option in form

Working on this form - form A trying to replicate the same behaviour as you can see in this one - form B. In the form B, if you click in the <label> of each option, it just works, while in form B, you have to click each one of the <input> elements if you want to make a different choice. Why?
Both samples have not CSS included, no CSS libraries loaded, it's just HTML
Form A
<form accept-charset="UTF-8" class="edit_order" id="edit_order_260" method="post">
<div style="display:none">
<input name="utf8" type="hidden" value="✓">
<input name="_method" type="hidden" value="put">
<input name="authenticity_token" type="hidden" value="N+XdGRhPcpB+999PYEU5Bs5bvdBYkLd4Ko+cNdhoppA=">
</div>
<h3 class="panel-title">
<label for="order_Best price"><input checked="checked" id="order_delivery_option_best_price" name="order[delivery_option]" onclick="enable_submit();" type="radio" value="best_price">
Best price</label>
</h3>
<h3 class="panel-title">
<label for="order_Best delivery date"><input id="order_delivery_option_best_delivery_date" name="order[delivery_option]" onclick="enable_submit();" type="radio" value="best_delivery_date">
Best delivery date</label>
</h3>
</form>
Form B
<form role="form">
<div class="radio">
<label><input type="radio" name="optradio">Option 1</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio">Option 2</label>
</div>
</form>
Just remove for attribute from the labels. For example:
<label><input checked="checked" id="order_delivery_option_best_price" name="order[delivery_option]" onclick="enable_submit();" type="radio" value="best_price">Best price</label>
Or make for value match the value of the id attribute of corresponding input tag. Like this:
<label for="order_delivery_option_best_price"><input checked="checked" id="order_delivery_option_best_price" name="order[delivery_option]" onclick="enable_submit();" type="radio" value="best_price">Best price</label>
In this case you don't have to nest the input inside the label and it will still work:)