multiple if condition in vuejs - how to get it work - vue.js

I literally just started messing aroung with vuejs. I'm having problem with multiple if conditions.
This is how I'm trying to get it work:
<td v-if="!editing && selectedID === user.id">{{user.name}}</td>
<td v-else>
<input type="text" v-model="user.name" />
</td>
User clicks on edit button and sets editing prop to true, then if next condition is true it should display input, but it doesnt work. Don't know why.

Your code should work if the rest of your code and markup is correct. Since we can't see the rest of your code, I will venture a guess that your "td" elements are not in a "table" element? If that is the case it won't work. See this working example to observe the difference https://jsfiddle.net/skribe/sLaf7m0e/
<!-- Working Code -->
<table>
<tr>
<td v-if="!editing && selectedId === user.id">{{user.name}}</td>
<td v-else>
<input type="text" v-model="user.name" />
</td>
</tr>
</table>
<!-- Non Working Code -->
<div>
<tr>
<td v-if="!editing && selectedId === user.id">{{user.name}}</td>
<td v-else>
<input type="text" v-model="user.name" />
</td>
</tr>
</div>
Why this is the case is if you inspect the dom you will find that because proper markup for tables is not used the tr and td elements are ignored causing all the fields to be rendered in a single div element.

you are showing input on the else case..... you have to do it like this instead :
<td v-if="editing && selectedID === user.id">
{{user.name}}
<input type="text" v-model="user.name"/>
</td>
<td v-else>
<!-- do something else if condition is false -->
</td>

Related

How can I add info icon with details next to input fields?

My input fields look like this:
<table class="something">
<tbody>
<tr>
<td style="vertical-align:top;width:60%;padding-right:25px">
<label><i class="far fa-calendar-alt"></i> Something:</label> (<em>something</em>) </td>
<td style="vertical-align:top;width:20%">
<label class="something" for="something">something:</label>
<input id="something" name="something" step="any" type="number" value=""> </td>
</tr>
</tbody>
</table>
How can I add an info icon with some text next to my inputs? I've found some solutions, but those are not fully responsive, they didn't work in all devices. A good example of what I want: https://bankmonitor.hu/lakashitel-kalkulator/?link_type=tile-menu-item
Thank you!

How to ignore that clicking on a TD tag does not automatically redirect me to another view? Vue

I have a table where in each TR when I click it redirects me to another view with the detail, the idea is that I have never worked with Vue and I can't think how to disable the event when I click on the first TD tag of the table.
Before in Jquery I did it this way:
//Add onclick to TR
$('table tr').click(function(e) {
// Avoid redirecting if it's a delete button
if(!$(e.currentTarget).hasClass('delete')) {
// Not a button, redirect by taking the attribute from data-route
window.location.href = $(e.currentTarget).data('route');
}
});
But with Vue I don't know how to do it in the onclick event.
This is my table and the method
<table
id="accounts-table"
class="
table table-listbox
table-bordered_
table-responsive-md
table-striped_
text-center_
"
>
<thead>
</thead>
<tbody>
<tr v-if="tableData.length === 0">
<td colspan="4" class="text-center">
No hay oportunidades para mostrar.
</td>
</tr>
<template v-if="loading === true">
<tr colspan="9" class="text-center">
<b-spinner variant="primary" label="Spinning"></b-spinner>
<b-spinner variant="primary" type="grow" label="Spinning"></b-spinner>
</tr>
</template>
<template v-else>
<tr
v-for="(data, k) in tableData"
:key="k"
#click="viewOpportunity(k, data)"
>
<slot :row="data">
<td v-if="permissions.includes('view all opportunities')" width="10">
<div class="iq-email-sender-info">
<div class="iq-checkbox-mail">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="mailk">
<label class="custom-control-label" for="mailk"></label>
</div>
</div>
</div>
</td>
<td width="20">
<vue-avatar
:username="data.sales_man"
:title="data.sales_man"
:size="32"
v-if="data.sales_man != ''"
></vue-avatar>
</td>
<td width="5">
<template v-if="data.has_file != false">
<i
class="ri-attachment-line"
style="font-size: 20px; color: #007bff"
></i>
</template>
</td>
<td width="120" nowrap>
<template>
<p class="mb-0">{{ data.created_at }}</p>
<small class="text-info mt-5">
Fecha creación
</small>
</template>
</td>
</slot>
</tr>
</template>
</tbody>
</table>
viewOpportunity(data) {
window.location.href = "/opportunity/" + data.id;
},
For example in the first TD of the table I would like that it does not redirect me to the page but from the 2nd TD it redirects me.
On first td element use this even modifier - #click.stop
Prevent on click on parent when clicking button inside div
This kind of issue ever answered .. please have a look on this
If someone needs an href inside a table that has a that has a #click method in the row, but you wat to the link does not fire the click event in the row and also to prevent event propagation when there is no method to call, e.g. a simple <a href="mailto:someone#example.org"> link, try to use this trick with #click.self:
BEFORE
<table>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>
<tr #click="myMethodFromRow">
<td>Some Value</td>
<td>
<a target="_blank" :href="mailto:someone#example.org"> My link </a>
</td>
</tr>
</table>
AFTER
<table>
<tr>
<th>COLUMN A</th>
<th>COLUMN B</th>
</tr>
<tr>
<td #click="myMethodFromRow">Some Value</td>
<td #click.self="myMethodFromRow">
<a target="_blank" :href="mailto:someone#example.org"> My link </a>
</td>
</tr>
</table>
In this case I wanted to execute myMethodFromRow clicking inside each td, but not clicking the link. So I changed the myMethodFromRow method from the tr and put it into each td. But the most important trik was to use #click.self for the td with the href link.
.self only trigger handler if event.target is the element itself, i.e. not from a child element.
DOCUMENTATION: https://vuejs.org/guide/essentials/event-handling.html#event-modifiers

Selenium - Navigation gets stuck after clicking a drop down (prior to an iframe switch)

The code clicks and pops up an overlay (successful). I am able to switch to iframe (using the driver.switchTo().frame(2)). Once selecting an element and clicking the Accept button, the overlay closes. Now I switch back to the main page using driver.switchTo().defaultContent(). The problem occurs soon after the code clicks a dropdown in the main page. This dropdown is not the typical Select or Option type (Select() or <option>). The elements are listed in a <table>.
There is no error displayed in the console but the program hangs. It stops the navigation after clicking the drop down and then no response.
Please find the html portion:
<input type="hidden" name="ctl00$cph$ctl02$TEST$FORM$ctl06$ctl32$ctl01$ctl03"
id="ctl00_cph_ctl02_TEST_FORM_ctl06_ctl32_ctl01_ctl03" />
<input type="hidden" name="ctl00$cph$ctl02$TEST$FORM$ctl06$ctl32$ctl01$ctl04"
id="ctl00_cph_ctl02_TEST_FORM_ctl06_ctl32_ctl01_ctl04" value="-1" />
<input type="hidden" name="ctl00$cph$ctl02$TEST$FORM$ctl06$ctl32$ctl01$ctl05" />
<input type="hidden" name="ctl00$cph$ctl02$TEST$FORM$ctl06$ctl32$ctl01$ctl06" />
<div id="ctl00_cph_ctl02_TEST_FORM_ctl06_ctl32_ctl01_outerFrame"
class="DropdownOuterContainer theme2 boarderA font7 shadow1" style="display:none;">
<div id="ctl00_cph_ctl02_TEST_FORM_ctl06_ctl32_ctl01_innerFrame"
class="DropdownInnerContainer" style="z-index:99;">
<table id="ctl00_cph_ctl02_TEST_FORM_ctl06_ctl32_ctl01_tbl"
class="DropdownItemContainer" list="120">
<tr class="">
<td value="" index="0" title="">
</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="Act1" index="1" plid="1001">Act1</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="Act2" index="2" plid="1002">Act2</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="Act3" index="3" plid="1003">Act3</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="Act4" index="4" plid="1004">Act4</td>
<td class="BorderCell"></td>
</tr>
</table>
In the code I am trying to select an option 'Act1' using the below statements. Note that only the first line executes, i.e, it clicks the drop down but then it doesn't move forward to the next step, where the selection happens.
driver.findElement(By.xpath(".//*[#id='ctl00_cph_ctl02_TEST$FORM_ctl06_ctl32_ctl01']")).click();
driver.findElement(By.xpath(".//*[#id='ctl00_cph_ctl02_TEST$FORM_ctl06_ctl32_ctl01_tbl']/tbody/tr/td[1][contains(text(),'Act1')]")).click();

Input field is filled, but content is not saved using Selenium IDE

Using Selenium IDE, I'm able to fill an input field (using "type" command), but when I "save" the value, this value is lost. Doing the same by hand, everything works fine.
Any hint to solve this issue? I've already tried using typeKeys command.
The code inside the target page is:
<!-- language-all: lang-html -->
<div id="editDiv" class="editDialog">
<table cellspacing="0" width="100%">
<tbody>
<tr>
<td width="25%" style="">period</td>
<td align="right" width="25%" style="padding: 6px;">
<input id="period" type="text" onblur="changeValue(this.id, this.value, undefined)">
<br>
<label>da 0 a 9</label>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" width="100%">
<input type="button" value="Save" onclick="applyChanges()">
<input type="button" value="Cancel" onclick="removeEditDialog(false)">
</div>
To help more on this issue:
function changeValue(id, value, paramPos) {
var par = tempGlobalParams[id] ? tempGlobalParams[id] : tempGlobalPaintingsParams[paramPos][id];
if(checkRules(id, value, paramPos)){
par.custom = value;
}

Add/remove row in a table

I have the following jquery code to add and remove a row in a table. I have multiple tables on one page. Each row in each table has these two classes: .row-add and .row-delete
Now when I click on '.row-add'to add a new row, all the tables are affected, meaning that row is added to all of the tables on the same page. What should I do to make it only apply to its own table when clicked?
Jquery:
$(document).ready(function () {
$('.row-delete').click(function () {
$(this).closest("tr").remove();
});
$('.row-add').click(function () {
$(this).closest("tr").clone(true).appendTo(".table-comparison");
});
});
Html:
<div id="tab-1" class="tab-section">
<div class="container flat rounded-sm bspace">
<table cellspacing="0" class="display table-comparison">
<thead>
<tr>
<th><span>Effective Date</span></th>
<th><span>Price</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><input class="effective-date" type="text" value="01/01/2013"> - <input class="effective-date" type="text" value="06/05/2015">
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="50">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
<tr class="price-present">
<td><input class="effective-date" type="text" value="07/01/2013"> - <span class="effective-date">Present</span>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="40">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
<tr>
<td><input class="effective-date" type="text" value="01/01/2011"> - <input class="effective-date" type="text" value="06/30/2012">
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="30">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
try to be specific ... closest("tr") you are selecting all trs.
try giving an ID, or class and select that id using jquery.
The problem is that your jQuery selector is on class attribute, if you want to refer to a single table, you have to go by id.
In this case I think the best approach is, if you generate programmatically the html code, to add to every table an auto generated id and to add to every clickable row the following code:
onclick="addrow(table_id)"
where table_id is the autogenerated id of the table. Then:
function addrow(table) {$(table).closest("tr").clone(true).appendTo(".table-comparison");}
Just be warned that also .table-comparison should be avoided switching to id, but I don't know the details of your code!
Hope this helps!
EDIT: still better, if you don't generate code, is the bind function, like
$("p").bind("click", function(event){
This way you can access ex-post who has sent the event.
In your case you I think you could write:
$(".row-delete").bind("click", function (event) {
event.target.closest("tr").remove();
});
$(".row-add").bind("click", function (event) {
event.target.closest("tr").clone(true).appendTo(".table-comparison");
});
Source: JQuery Doc