Vuejs counter condition not working when value is reset - vue.js

I'm trying to implement a datepicker where you flick through the months.
The objective is to reset the month counter when it reaches -1 or 11.
Counting up, it works just fine, but counting down it does not reset the value once it reaches -1 and I don't understand why.
<template>
<div id="app">
<button #click="count(1)">Count up</button>
<button #click="count(-1)">Count down</button>
<button #click="reset">reset</button>
<div>Value: {{ value }}</div>
</div>
</template>
methods: {
reset(){ this.value = 5 },
count(num) {
var x = this.value + num;
console.log(x)
if (x < 0) {
this.value = 11;
}
if (x > 11) {
this.value = 0;
} else {
this.value = x;
}
}
},
data() {
return {
value: 5,
};
},
Here's the code sandbox

Update your code to
if (x < 0) {
this.value = 11;
} else if (x > 11) {
this.value = 0;
} else {
this.value = x;
}
And it will work :)
The reason is that for now when the value is less than 0 it enters the first condition (if (x < 0)) and then it still enters the else so this.value is set to x.

Related

Change value after confirmation in input VUE-JS

I have a table with an input column. This input column will have value if it has been saved in ddbb before.
If this value changes, handled with an event '#blur', I show a modal to confirm the change.
My problem is that if you want to keep the old value it will always change...
I tried to change this value with javascript, but it doesn't work... Any suggestions?
This is my code:
<b-tbody>
<b-tr
v-for="(driver, index) in drivers"
:key="driver.clientId">
<b-td
data-label="Client"
:title="driver.clientName">{{ driver.clientName }}</b-td>
<b-td data-label="Numerator">
<b-input
:id="'numeratorDriver_'+index"
class="driver-numerator text-right"
type="text"
:value="(driver.driverNumerator === undefined) ? 0 : $utils.formatNumber(driver.driverNumerator)"
#blur="calculatePricingDriver($event, index)" /></b-td>
<b-td
class="text-right"
data-label="Pricing"
:title="driver.pricingDriver"><span>{{ driver.pricingDriver }}</span></b-td>
</b-tr>
</b-tbody>
<script>
function calculatePricingCustomDriver (event, index) {
let lastValue = this.drivers[index].driverNumerator
if (this.$store.getters.price !== undefined) {
let title = 'Modify numerator'
let message = 'If you modify numerator driver, the calculated pricing will be deleted'
this.$bvModal.msgBoxConfirm(message, {
title: title,
size: 'sm',
buttonSize: 'sm',
okTitle: 'Yes',
okVariant: 'primary',
cancelTitle: 'No',
cancelVariant: 'primary',
hideHeaderClose: false,
centered: true
})
.then(confirmed => {
if (confirmed) {
this.$http.get('delete-price', { params: { id: this.$store.getters.id } })
.then((response) => {
if (response.status === this.$constants.RESPONSE_STATUS_OK) {
this.price = ''
let newNumerator = event.target.value
this.drivers[index].driverNumerator = Number(newNumerator)
let sumTotal = _.sumBy(this.drivers, 'driverNumerator')
for (let i = 0; i < this.drivers.length; i++) {
this.drivers[i].pricingDriver = (this.drivers[i].driverNumerator / sumTotal).toFixed(2)
}
} else {
this.drivers[index].driverNumerator = lastValue
// this is that I want change because it doesn't work fine
document.getElementById('numeratorDriver_' + index).value = lastValue
}
})
} else {
this.drivers[index].driverNumerator = lastValue
document.getElementById('numeratorDriver_' + index).value = lastValue
}
})
.catch(() => {
/* Reset the value in case of an error */
this.$utils.showModalError()
})
} else {
let newNumerator = event.target.value
this.drivers[index].driverNumerator = Number(newNumerator)
let sumTotal = _.sumBy(this.drivers, 'driverNumerator')
for (let i = 0; i < this.drivers.length; i++) {
this.drivers[i].pricingDriver = (this.drivers[i].driverNumerator / sumTotal).toFixed(2)
}
}
}
</script>
how is calculatePricingCustomDriver being loaded into your Vue component? For it to be called like that from #blur you would need to define it as a method:
<template>
<!-- your table-->
</template>
<script>
export default {
name: "MyComponent",
methods : {
calculatePricingCustomDriver () {
// your code
}
}
}
</script>
Or it could be installed as a global mixin

Error message showing after cleannig inputs with Vue

I have a simple form to update a password with 3 inputs (old_password, new_password and new_password_confirmation).
After the submit, if it is updated successfully, the inputs are cleaned. The problem is that after this, the input errors are showed even when the conditional is false.
This is one of the inputs:
<input type="password" v-model="old_password">
<small class="text-danger" v-if="errors.old_password != ''">{{errors.old_password}}</small>
The logic:
<script>
export default {
data() {
return {
old_password: '',
errors: []
}
},
watch: {
old_password(value) {
this.old_password = value
if(value.length < 3) {
this.errors.old_password = 'Debes ingresar al menos 4 caracteres'
} else {
this.errors.old_password = ''
}
}
},
methods: {
updatePassword() {
this.$store.dispatch('updatePassword', data)
.then(response => {
this.old_password = ''
this.errors.old_password = ''
})
.catch(error => {
})
}
}
}
</script>
Because once input becomes empty your condition value.length < 3 is true and error will be shown
Simply add to your condition this one && value.length > 0
So the final code will look like
if(value.length < 3 && value.length > 0) {
this.errors.old_password = 'Debes ingresar al menos 4 caracteres'
} else {
this.errors.old_password = ''
}
Also, errors should be an object instead of an array - errors: {}

weex input number limit

use component, when i input content,it has a limit condation,only input number length is 8,and only 2 radix point,for example,can input 123.45, 123.456 is not.
<input :type="type"
v-model="inputValue"
:max-length="maxInputLength"
:maxlength="maxInputLength"
:placeholder="rightPlaceholder"
:class="['input', disabled ? 'input-style-disabled' : '']"
:disabled="disabled"
#input="onTextChange"/>
and data is :
data () {
return {
inputValue:'', //input value
}
},
mounted(){
if(this.value) {
this.inputValue = this.value;
}
},
methods:{
formatAmount(value){
let result;
if (value.indexOf(".") > 0 && value.length - value.indexOf(".") >= 4){
result = value.substr(0,value.indexOf('.') + 3);
// fValue = value.toFixed(2);
Log.d("formatAmount",result);
}else {
result = value;
Log.d("formatAmount else",result);
}
return result;
},
onTextChange() {
setTimeout(() => {
this.inputValue = this.formatAmount(this.inputValue);
this.$emit("onTextChange",this.inputValue);
}, 10);
}
}
totally,this just work when two point change to three point,then still can input three point.
how does it work,need help.thx.
You can use array split on (.) and then check arr[1].length<=2 and arr[0].length <=6.or use regex /^\d+(.\d{1,2})?$/ for 2 radix point;

filter content with categories and keywords in vuejs

I am having a pretty big problem I have the following code and I have buttons to try to filter videos based on what category or keyword they have associated with them. However I am getting duplicates in the filter method I wrote. to make matters worse some of the content doesn't even display.
I have the following variables in my data property
data :{
loggedIn: true,
displayCount:36,
searchQuery:'',
templateArray:[],
filteredTemplateArray:[],
categories: [],
keywords:[],
selectedCategories:[],
selectedKeywords:[],
sortBy:''
},
when thea page loads templateArray and filteredTemplateArray are both equal to
[{"id":"7","itemId":"17520","itemName":"Arrow
Bounce","thumbName":"ARROWBOUNCE","dateAdded":"2016-05-20
16:33:42","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/ArrowBounce-Scott/arrowBounce.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":["LensFlare"]},{"id":"11","itemId":"38752","itemName":"Jitter
Zoom Flash","thumbName":"JITTERZOOMFLASH","dateAdded":"2016-05-23
13:49:03","renderTime":"45","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/JitterZoomFlash-Scott/JitterZoomFlash.aep","stillImageLocation":"2.66","categoryArray":["Sports"],"keywordArray":["Snow","Sparkles"]},{"id":"12","itemId":"12737","itemName":"Cloth
Drop","thumbName":"CLOTHDROP","dateAdded":"2016-05-23
14:11:42","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/ClothDrop-Scott/cloth
drop.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"15","itemId":"73076","itemName":"Colorful
Trans","thumbName":"COLORFULIMAGETRANS","dateAdded":"2016-05-27
10:16:56","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/ColorfulImageTrans-Scott/ColorfulImageTrans.aep","stillImageLocation":"12.90","categoryArray":[],"keywordArray":["Water","Sparkles"]},{"id":"16","itemId":"18488","itemName":"Convex
½
Circle","thumbName":"CONVEXHALFCIRCLE","dateAdded":"2016-05-27
10:38:20","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/convexHalfCircle-Scott/convex
half
circle.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"17","itemId":"67039","itemName":"Flag
Swap","thumbName":"FLAGBACKSWAP","dateAdded":"2016-06-01
15:34:22","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/FlagBackSwap-Scott/FlagBackSwap.aep","stillImageLocation":"5.83","categoryArray":[],"keywordArray":[]},{"id":"31","itemId":"70006","itemName":"Flag
Raise","thumbName":"FLAGRAISE","dateAdded":"2016-06-03
11:13:37","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/FlagRaise-Scott/flag.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"32","itemId":"58759","itemName":"Logo
Dust Poof","thumbName":"LOGODUSTPOOF","dateAdded":"2016-06-03
11:25:34","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/LogoDustPoof-Scott/LogoDustPoof.aep","stillImageLocation":"6.23","categoryArray":[],"keywordArray":[]},{"id":"33","itemId":"58967","itemName":"Flag
Wave (Loop)","thumbName":"FLAGWAVE","dateAdded":"2016-06-03
11:35:49","renderTime":"75","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/FlagWave-Scott/FlagWave.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"34","itemId":"65288","itemName":"Logo
Splash One","thumbName":"LOGOSPLASHONE","dateAdded":"2016-06-03
15:34:19","renderTime":"45","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/LogoSplashOne-Scott/LogoSplashOne.aep","stillImageLocation":"2.70","categoryArray":[],"keywordArray":[]},{"id":"35","itemId":"91246","itemName":"Metal
Sparks","thumbName":"METALSPARKS","dateAdded":"2016-06-06
10:58:29","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/MetalSparks-Scott/MetalSparks.aep","stillImageLocation":"4.63","categoryArray":[],"keywordArray":[]},{"id":"36","itemId":"57489","itemName":"Middle
Stripe","thumbName":"MIDDLESTRIPEABA","dateAdded":"2016-06-06
12:25:41","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/MiddleStripe-Scott/middleStripeABA.aep","stillImageLocation":"6.80","categoryArray":[],"keywordArray":[]},{"id":"37","itemId":"38402","itemName":"Water
One","thumbName":"WATERONE","dateAdded":"2016-06-07
09:10:32","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/waterOne-Scott/waterOne.aep","stillImageLocation":"8.83","categoryArray":[],"keywordArray":[]},{"id":"39","itemId":"81031","itemName":"Oval
Text Flip","thumbName":"OVALTEXTFLIP","dateAdded":"2016-05-07
09:10:32","renderTime":"150","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/OvalTextFlip-Scott/OvalTextFlip.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"40","itemId":"55143","itemName":"Close
Up Text","thumbName":"CLOSEUPTEXT","dateAdded":"2016-07-05
09:10:32","renderTime":"85","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/CloseUpText-Scott/CloseUpText/CloseUpText.aep","stillImageLocation":"9.03","categoryArray":[],"keywordArray":[]},{"id":"41","itemId":"54335","itemName":"Electric
Text Spin","thumbName":"ELECTRICTEXTSPIN","dateAdded":"2016-07-13
09:10:32","renderTime":"60","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/ElectricTextSpin-Scott/ElectricTextSpin/ElectricTextSpin.aep","stillImageLocation":"1.47","categoryArray":[],"keywordArray":[]},{"id":"42","itemId":"23761","itemName":"Digital
Glitch","thumbName":"DIGITALGLITCH","dateAdded":"2016-09-19
09:10:32","renderTime":"60","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/DigitalGlitch-Scott/DigitalGlitch.aep","stillImageLocation":"3.43","categoryArray":["Retail"],"keywordArray":[]},{"id":"43","itemId":"56465","itemName":"Takeover","thumbName":"TAKEOVER","dateAdded":"2016-09-30
14:10:32","renderTime":"80","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/TakeOver-Scott/TakeoverProject/takeoverproject.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"44","itemId":"17127","itemName":"Fire
One","thumbName":"FIREONE","dateAdded":"2016-11-04
14:10:32","renderTime":"25","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/FireOne-Scott/FireOne.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"53","itemId":"61617","itemName":"City
Spin","thumbName":"CITYSPIN","dateAdded":"2016-11-09
14:17:15","renderTime":"45","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2016/CitySpin-Scott/cityspin.aep","stillImageLocation":"8.933","categoryArray":["Church"],"keywordArray":[]},{"id":"56","itemId":"15528","itemName":"Magic
Colors","thumbName":"MAGICCOLORS","dateAdded":"2016-11-10
13:10:26","renderTime":"30","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/MagicColors-Scott/MagicColors.aep","stillImageLocation":"3.966","categoryArray":[],"keywordArray":[]},{"id":"61","itemId":"59239","itemName":"Quick
and Simple","thumbName":"QUICKNSIMPLE","dateAdded":"2016-11-14
11:42:09","renderTime":"15","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/QuickNSimple-Scott/QuickNSimple.aep","stillImageLocation":"2.033","categoryArray":[],"keywordArray":[]},{"id":"62","itemId":"82460","itemName":"Fast
Blast","thumbName":"FASTBLAST","dateAdded":"2016-11-22
10:24:48","renderTime":"30","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/FastBlast-Scott/FastBlast.aep","stillImageLocation":"9.666","categoryArray":[],"keywordArray":[]},{"id":"63","itemId":"83530","itemName":"Tunnel
Spin","thumbName":"TUNNELSPIN","dateAdded":"2016-12-02
13:09:06","renderTime":"20","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/tunnelSpin-Scott/tunnelSpin.aep","stillImageLocation":"2.9","categoryArray":[],"keywordArray":[]},{"id":"64","itemId":"94148","itemName":"Sparkle
Splash","thumbName":"SPARKLESPLASH","dateAdded":"2016-12-20
11:23:26","renderTime":"45","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2016/SparkleSplash-Scott/SparkleSplash.aep","stillImageLocation":"6.1","categoryArray":[],"keywordArray":[]},{"id":"69","itemId":"98640","itemName":"Gold
Bling","thumbName":"GOLDBLING","dateAdded":"2017-01-10
08:16:41","renderTime":"30","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/GoldBling-Joe/GoldBling.aep","stillImageLocation":"2.66","categoryArray":[],"keywordArray":[]},{"id":"72","itemId":"94169","itemName":"Top
Racer","thumbName":"TOPRACER","dateAdded":"2017-02-15
09:46:14","renderTime":"30","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/TopRacer-Scott/TopRacer.aep","stillImageLocation":"7.833","categoryArray":[],"keywordArray":[]},{"id":"73","itemId":"55871","itemName":"Desert
Sand","thumbName":"DESERTSAND","dateAdded":"2017-02-15
14:04:49","renderTime":"45","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/DesertSand-Scott/DesertSand.aep","stillImageLocation":"10.46","categoryArray":[],"keywordArray":[]},{"id":"76","itemId":"18897","itemName":"Electric
Storm","thumbName":"ELECTRICSTORM","dateAdded":"2017-02-23
12:43:08","renderTime":"45","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/ElectricStorm-Scott/ElectricStorm.aep","stillImageLocation":"4.333","categoryArray":[],"keywordArray":[]},{"id":"78","itemId":"24052","itemName":"Court
Smash","thumbName":"COURTSMASH","dateAdded":"2016-06-03
12:03:48","renderTime":"90","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/CourtSmash-Scott/CourtSmash.aep","stillImageLocation":"5.933","categoryArray":[],"keywordArray":[]},{"id":"81","itemId":"43553","itemName":"Tile
Flip","thumbName":"TILEFLIP","dateAdded":"2017-04-25
16:40:41","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/TileFlip-Chris/TileFlip_Final/TileFlip_Final.aep","stillImageLocation":"5","categoryArray":[],"keywordArray":[]},{"id":"88","itemId":"94677","itemName":"NEON
LIGHTS","thumbName":"NEONLIGHTS","dateAdded":"2017-04-28
10:06:23","renderTime":"45","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/NEONLIGHTS-Joe/NeonLights.aep","stillImageLocation":"2.53","categoryArray":[],"keywordArray":[]},{"id":"89","itemId":"64305","itemName":"Engine
(Loop)","thumbName":"ENGINE","dateAdded":"2017-05-15
11:37:07","renderTime":"60","tested":"1","projectPath":"O:/Projects/Generics/CreativeEngine/2017/Engine-Scott/Engine.aep","stillImageLocation":"4.67","categoryArray":[],"keywordArray":[]},{"id":"90","itemId":"11287","itemName":"Energy
Core","thumbName":"ENERGYCORE","dateAdded":"2017-05-22
13:08:40","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/EnergyCore-Scott/EnergyCore.aep","stillImageLocation":"6.73","categoryArray":[],"keywordArray":[]},{"id":"91","itemId":"48745","itemName":"Football
Helmet","thumbName":"FOOTBALLHELMET","dateAdded":"2017-07-03
16:09:42","renderTime":"120","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/FootballHelmet-Scott/FootballHelmet.aep","stillImageLocation":"7","categoryArray":[],"keywordArray":[]},{"id":"92","itemId":"85515","itemName":"Light
Shine","thumbName":"LIGHTSHINE","dateAdded":"2017-08-18
14:09:50","renderTime":"30","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/LightShine-Scott/LightShine.aep","stillImageLocation":"2","categoryArray":[],"keywordArray":[]},{"id":"93","itemId":"61876","itemName":"Baseball
Dirt","thumbName":"BASEBALLDIRT","dateAdded":"2017-08-31
10:31:22","renderTime":"40","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/BaseballDirt-Scott/BaseballDirt.aep","stillImageLocation":"7.27","categoryArray":[],"keywordArray":[]},{"id":"94","itemId":"48066","itemName":"Spooky","thumbName":"SPOOKY","dateAdded":"2017-09-01
13:58:36","renderTime":"15","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/Spooky-Jake/Spooky.aep","stillImageLocation":"2","categoryArray":["Sports"],"keywordArray":[]},{"id":"95","itemId":"33584","itemName":"Get
Loud","thumbName":"GETLOUD","dateAdded":"2017-09-07
11:58:02","renderTime":"45","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/GetLoud-Scott/GetLoud.aep","stillImageLocation":"1.77","categoryArray":[],"keywordArray":[]},{"id":"96","itemId":"21713","itemName":"STAR
BURST","thumbName":"STARBURST","dateAdded":"2017-10-19
18:20:29","renderTime":"15","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/StarBurst-Joe/StarBurst.aep","stillImageLocation":"0","categoryArray":[],"keywordArray":[]},{"id":"97","itemId":"76554","itemName":"Magic
Twirl","thumbName":"MAGICFINAL","dateAdded":"2017-10-26
11:19:52","renderTime":"20","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/Magic-Lillie/Magic.aep","stillImageLocation":"825","categoryArray":[],"keywordArray":[]},{"id":"98","itemId":"64452","itemName":"Sports
Car","thumbName":"SPORTSCAR","dateAdded":"2017-10-27
10:26:32","renderTime":"60","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/SportsCar-Scott/SportsCar.aep","stillImageLocation":"14.77","categoryArray":[],"keywordArray":[]},{"id":"99","itemId":"15074","itemName":"Ice
Logo","thumbName":"ICELOGO","dateAdded":"2017-11-01
11:53:48","renderTime":"45","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/IceLogo-Scott/IceLogo.aep","stillImageLocation":"9.33","categoryArray":[],"keywordArray":["LensFlare"]},{"id":"100","itemId":"95033","itemName":"Hot
Air Balloon","thumbName":"BALLOON","dateAdded":"2017-11-02
08:10:22","renderTime":"10","tested":"1","projectPath":"M:/Projects/Generics/CreativeEngine/2017/Balloon-Lillie/Balloon.aep","stillImageLocation":"567","categoryArray":[],"keywordArray":[]},{"id":"231","itemId":"bb39f253c6c237ecf5d86ced4e8bcdec","itemName":"test","thumbName":"TEST","dateAdded":"2018-09-28
18:35:08","renderTime":"4","tested":"0","projectPath":"M:/Projects/Generics/uploads/testLocation","stillImageLocation":"0.13","categoryArray":["Sports","Misc","Holiday"],"keywordArray":{"0":"LensFlare","2":"Snow","5":"Water"}}]
categories looks like this
["Holiday","Sports","Misc","Automotive","Retail","Financial","Church","Community","Food"]
keywords is the same as categories just different values
when a button is clicked selectedCategories begins to fill up with an array that looks like this :
0: "Holiday"
selectedKeywords like this (if its a keyword button instead of a category):
0: "lensFlare"
when a button gets pressed filteredTemplates looks like this in the vue inspector:
> filteredTemplateArray:Array[1] 0:Object categoryArray:Array[3]
> 0:"Sports" 1:"Misc" 2:"Holiday" dateAdded:"2018-09-28 18:35:08"
> id:"231" itemId:"bb39f253c6c237ecf5d86ced4e8bcdec" itemName:"test"
> keywordArray:Object
> projectPath:"M:/Projects/Generics/uploads/testLocation" renderTime:"4"
> stillImageLocation:"0.13" tested:"0" thumbName:"TEST"
I have the following method filtering the items when pressed but its not working how would ya'all change it so that all the items show up and items are filtered properly?
filter: function() {
var filteredCategoryArray = [];
var filteredKeywordArray = [];
if(this.selectedCategories.length != 0) {
for(var i = 0; i < this.templateArray.length; i++) {
for(var j = 0; j < this.selectedCategories.length; j++ ) {
for(var k = 0; k < this.templateArray[i].categoryArray.length; k++ ) {
if(this.templateArray[i].categoryArray[k] == this.selectedCategories[j]) {
var arrayDuplicate = false;
for(var l = 0; l < filteredKeywordArray.length; l++) {
if(filteredCategoryArray[l].id == this.templateArray[i].id) {
arrayDuplicate = true;
}
}
if(arrayDuplicate == false) {
filteredCategoryArray.push(this.templateArray[i]);
}
}
}
}
}
} else {
for(var i = 0; i < this.templateArray.length; i++){
filteredCategoryArray.push(this.templateArray[i]);
}
}
if(this.selectedKeywords.length != 0) {
for(var i = 0; i < filteredCategoryArray.length; i++) {
for(var j = 0; j < this.selectedKeywords.length; j++ ) {
for(var k = 0; k < filteredCategoryArray[i].keywordArray.length; k++ ) {
if(filteredCategoryArray[i].keywordArray[k] == this.selectedKeywords[j]) {
var arrayDuplicate = false;
for(var l = 0; l < filteredKeywordArray.length; l++) {
if(filteredKeywordArray[l].id == filteredCategoryArray[i].id) {
arrayDuplicate = true;
}
}
if(arrayDuplicate == false) {
filteredKeywordArray.push(filteredCategoryArray[i]);
}
}
}
}
}
} else {
for(var i = 0; i < filteredCategoryArray.length; i++){
filteredKeywordArray.push(filteredCategoryArray[i]);
}
}
if(this.sortBy == "az") {
filteredKeywordArray.sort(function(a,b) {
if(a.itemName > b.itemName) {
return 1;
}
if(a.itemName < b.itemName) {
return -1;
}
return 0;
});
}
if(this.sortBy == "dateAdded") {
filteredKeywordArray.sort(function(a,b) {
if(a.dateAdded < b.dateAdded) {
return 1;
}
if(a.dateAdded > b.dateAdded) {
return -1;
}
return 0;
});
}
if(this.sortBy == "renderTime") {
filteredKeywordArray.sort(function(a,b) {
return parseInt(a.renderTime) - parseInt(b.renderTime);
});
}
this.filteredTemplateArray = filteredKeywordArray;
$('html,body').scrollTop(0);
},
heres the front end loop to show the videos
<div class="row">
<div v-cloak v-bind:key="template.itemId + '_' + index" v-for="(template, index) in searchResults" class="col-md-4">
<div class="card">
<video muted :src="'mysource'" controls preload="none" controlsList="nodownload nofullscreen" :poster="mysource" loop="loop"></video>
<div class="card-body">
<p class="card-title">{{template.itemName}}</p>
<!--end card-title-->
<p v-show="displayCount==0" class="card-text">Please create a display to customize</p>
<!--end user has no display card-text-->
<p v-show="displayCount>0" class="card-text">Custom Text, Custom Colors, Upload Logo</p>
<!--end user has display card text-->
<p class="card-text">{{template.renderTime}} minutes</p>
Customize
<!--logged in and has display button-->
<a href="#" v-show="loggedIn==false" class="btn btn-primary btn-block" disabled>Customize</a>
<!--not logged in button-->
Create A Display
</div>
<!--end card-body-->
</div>
<!--end card-->
</div>
<!-- end col-md-4-->
</div>
<!--end row-->

Vue.js - Input, v-model and computed property

I'm using vue-2.4 and element-ui 1.4.1.
Situation
I have a basic input which is linked with v-model to a computed property. When blur I check if the value input is greater or lower than min and max and I do what I have to do ... Nothing fancy here.
Problem
The value displayed in the input does not always equal enteredValue
Steps to reproduce
1) Input 60 --> Value displayed is the max so 50 and enteredValue is 50 (which is ok)
2) Click outside
3) Input 80 --> Value displayed is 80 and enteredValue is 50
Questions
How can I fix that so the value displayed is always the same as the enteredValue ?
Here is the minimal code to reproduce what I'm facing JSFIDDLE
<div id="app">
The variable enteredValue is {{enteredValue}}
<el-input v-model="measurementValueDisplay" #blur="formatInput($event)"></el-input>
</div>
var Main = {
data() {
return {
enteredValue: '',
max: 50,
min: 10
}
},
computed: {
measurementValueDisplay: {
get: function () {
return this.enteredValue + ' inchs'
},
set: function (newValue) {
}
},
},
methods: {
formatInput($event) {
let inputValue = $event.currentTarget.value;
if (inputValue > this.max) { this.enteredValue = this.max}
else if (inputValue < this.min) { this.enteredValue = this.min}
else this.enteredValue = inputValue
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
Reading this vuejs, will understand what happens
"computed properties are cached based on their dependencies. A computed property will only re-evaluate when some of its dependencies have changed."
Changed some comportament of the code. Made run:
computed() method not works properly for update value in window. But if looks at console the value yes updated.
So, i remove computed (getter and setter), and put into data, without setter and getter( i dont like this in javascript).
var Main = {
data() {
return {
measurementValueDisplay:'fff',
enteredValue: '',
max: 50,
min: 10
}
},
computed: {
/*measurementValueDisplay: {
get: function () {
console.log('Computed was triggered so I assume enteredValue changed',this.enteredValue);
return this.enteredValue + ' inchs'
},
set: function (newValue) {
console.log('setter de qye', this.enteredValue);
}
},*/
},
methods: {
formatInput($event) {
this.enteredValue = 0;
let inputValue = $event.currentTarget.value;
console.log(inputValue);
if (inputValue > this.max) { this.enteredValue = this.max}
else if (inputValue < this.min) { this.enteredValue = this.min}
else this.enteredValue = inputValue
this.measurementValueDisplay = this.enteredValue + ' inchs'
console.log(this.enteredValue, 'oioioioio0');
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
Your problem is that the values used in the computed property was not updated with the validation capping at 50 (Was 50, is now updated to 50, no need to recalculate), therefore v-model did not update the input.
I've edited your jsfiddle to use two computed properties:
One with an accessor to validate the entered value, one which returns the value with " inch" appended.
Here is the interesting part:
computed: {
measurementValueDisplay: {
get: function () {
return this.enteredValue
},
set: function (newValue) {
this.enteredValue = 0;
let inputValue = parseInt(newValue);
if(Number.isNaN(inputValue)){this.enteredValue = this.min}
else if (inputValue > this.max) { this.enteredValue = this.max}
else if (inputValue < this.min) { this.enteredValue = this.min}
else this.enteredValue = inputValue
}
},
valueWithInch(){
return this.enteredValue + " inch";
}
},
In case anybody still needs a hack for this one, you can use a value that will always change ( for example a timestamp )
var Main = {
data() {
return {
enteredValue: '',
max: 50,
min: 10,
now: 1 //line added
}
},
computed: {
measurementValueDisplay: {
get: function () {
return (this.now - this.now + 1 ) * this.enteredValue + ' inchs'; //line changed
},
set: function (newValue) {
this.now = Date.now(); //line added
}
},
},
methods: {
formatInput($event) {
let inputValue = $event.currentTarget.value;
if (inputValue > this.max) { this.enteredValue = this.max}
else if (inputValue < this.min) { this.enteredValue = this.min}
else this.enteredValue = inputValue
}
}
}