How to change the label name dynamically in vs-tab using vue.js - vue.js

<vs-tab lable="Kid 1" >
<vs-tab lable="Kid 2" >
and so on...
I made the dynamically add kid and used this like
<vs-tab lable="Kid 1" v-for"(kid,index) in kids>
I mean this lable="Kid{{index+1}} but showing error plz help me out..

You should replace your code to this:
<vs-tab :label="'Kid ' + (index + 1)" v-for"(kid,index) in kids">

And to complete the right answer from #webprogrammer don't forget: for a v-for you need to add a unique key, for instance : :key="index"

Related

Odoo 11: How to correctly implement #api.onchange?

I want to compute a telephone number, if the number in the 8 position is either "0" or "1" I want to print just the last 4 numbers with a "(3)" before them, otherwise just print the 4 numbers, but what is happening is that my code is printing "0.0" and I don't know why, I'll appreciate your help...
This is my python code:
class Employee(models.Model):
_inherit = "hr.employee"
marcado_rapido = fields.Float("MarcadoRapido",compute='_compute_marcado_rapido')
#api.onchange("emp.marcado_rapido")
def onchange_compute_marcado_rapido(self):
for num in self:
num = "809-257-1457"
if num[8] in ('0','1'):
"(3)"+num[8:]
This is my xml code:
<td>
<t t-foreach="env['hr.employee'].search([('department_id', '=', dep.id)])" t-as="emp">
<div class="contact_form">
<img t-if="emp.image" t-att-src="'data:image/png;base64,%s' % to_text(emp.image)"/>
<div class="bloqueP">
<div class="bloque" t-field="emp.marcado_rapido"/>
</div>
</div>
</t>
</td>
#onchange only supports simple field names, dotted names (fields of relational fields e.g. partner_id.tz) are not supported and will be ignored
You can check the official documentation on how the onchange decorator works and what are the limitations.
0.0 is the default value for float fields and the value of marcado_rapido is computed using _compute_marcado_rapido function. If the field updated in onchange method depends on marcado_rapido field value, you can compute its value using the same method
You should use compute decoration instead of onchange, but compute method aproach always depend in someone else field. My sugestion is use a another computed field, something like this:
class Employee(models.Model):
_inherit = 'hr.employee'
# If your number contains special characters(like '-') you should use `Char` insted of `float`
num_telefono = fields.Char('Num. Telefono')
marcado_rapido = fields.Char('MarcadoRapido', compute='_compute_marcado_rapido')
#api.depends('num_telefono')
def _compute_marcado_rapido(self):
for rec in self:
num = rec.num_telefono[-4:]
rec.marcado_rapido = '(3){}'.format(num) if num[:1] in ('0','1') else num
Now you can call marcado_rapido from your XML.
I hope this answer can be helful for you.

Pass parameter in v-bind:href

I have a <a> tag in my vue component & by checking some condition v-bind:href may differ. I have used ternary operator for it and in the else part I want to pass id with the url, but with not as part of url (like '/test/' +id). id should not be in the url. so how to do it?
This is how I tried for it & it giving me the compile error due to comma before id in else part,
<a v-bind:href="type === 'single' ? '/user/'+user.id+'/edit' : '/profile',user.id">
Url should be like "/profile"
I have resolved it as follows,
<a v-bind:href="type === 'single' ? '/user/'+user.id+'/edit' : '/profile?user_id='+user.id">

Syntax of Vue.js filter within v-bind:href

I am declaring a html hyperlink with vue.js. The URL is set up by concatenating lets say "baseurl" and "id". However, I need to format the "id" first. I am trying to use a vue.js filter to process the "id" before concatenating with "baseurl". However, the filter applies to the whole URL, and not just to "id", which is what I want.
Let's say:
longid = "myprefix.id"
I want to obtain:
longid
I got this if I do:
<a v-bind:href="'https://mysite.mydatabase?ID='+longid.substring(longid.indexOf('.')+1)">{{ longid }}</a>
However, I wanted to do it with a vue.js filter, which I like more. I tried:
<a v-bind:href="'https://mysite.mydatabase?ID='+longid | shorten">{{ longid }}</a>
With the filter declared as:
filters: {
shorten: function(myString){
return myString.substring(myString.lastIndexOf(".")+1)
}
},
This is applied to the whole URL, and not just to "longid", so I finally have:
href="id"
instead of
href="https://mysite.mydatabase?ID=id"
I also tried to enclose the substring and the filter within parentheses:
<a v-bind:href="'https://mysite.mydatabase?ID='+ ( longid | shorten )">{{ longid }}</a>
but then I got a ReferenceError claming that the filter is not defined.
How can I make the filter apply only to "longid", being afterwards concatenated with the rest of the URL?
From what I get here is that you are trying to use a filter as method. You can achieve this using this.$options.filters.filterName().
For the given case, you should try something like:
<a v-bind:href="'https://mysite.mydatabase?ID='+$options.filters.shorten(longid )">{{ longid }}</a>.
Fiddle for reference: https://jsfiddle.net/sharitu/nbm2v1dx/3/
You can define method shorten and use like
<a v-bind:href="`https://mysite.mydatabase?ID=${shorten(longid)}`">{{ longid }}</a>
Consider change your shorten function:
shorten: function(myString){
return myString.split('.').pop()
}
Try this:
<a v-bind:href="'https://mysite.mydatabase?ID='+longid | shorten(longid)">{{ longid }}</a>
Your filters function should change like this:
filters: {
shorten: function(myString,longid){
//return your code;
}
},
First argument is the url and second argument is longid parameter

Empy list on return

I have this in my qweb report
<span t-esc="formatLang(get_routing_data(o)[-1]['total'] , digits=3)"/>
it works ok, but sometimes it returns an empty list and then i get error index tuple out of range. how can i avoid it?
You could set the return value of the call to get_routing_data into a variable and make check the value using t-if conditions before use it, like:
<t t-set="routing_data" t-value="get_routing_data(o)"/>
<span t-if="routing_data and len(routing_data) > 0 and routing_data[-1].get('total', False)" t-esc="formatLang(routing_data[-1]['total'], digits=3)"/>

Binding Expression in Aurelia if.bind

I would like to put in a simple expression to a template in Aurelia.
When working in a loop of <span repeat.for="link of links">, I want to show a '/' between all items, except after the last one.
I would expect I could use the following:
<span if.bind="${$index + 1} !== ${links.length}"> / </span>
But this gives me the following error:
Uncaught (in promise) Error: Parser Error: Missing expected : at column 10 in [${$index + 1} !== ${links.length}]
Is there a way I can do this?
Try if.bind="$index !== links.length - 1" instead of doing string interpolation. That should make it work.
or even shorter:
<span>${links.join(' / ')}</span>