Vue v-if doesn't refresh when value is changed - vue.js

I created a formular where the user can fill out one to infinite Forumlars, for this i made a state were the formular data is stored as an array of objects. One forumluar is a object and when the user creates a new Formular a new object is pushed in the array.
Each Formular beginns with one field which after filled out gets checked if it already exists if not it should open up the other field underneath it.
<template v-if="$store.state.Zell_Open[$store.state.PAGENUMBER]===true">
The Checked state is a array of booleans for each Formular one Bool.
If the Users Checks the state gets Updated correctly and the Zell_Open state is turned to true
Heres my whole state after checking
The Problem is that rest of the formular that should be shown after checking and putting the Zell_Open state on true isnt shown.
If i change the PAGENUMBER state manually (with vue dev tools) one up and down then its shown correctly.
Before i added the [$store.state.PAGENUMBER] part and when the Zell_Open state wasnt a array but instead a single bool (at first it should be just one formular not one to infinite) it worked perfectly fine.
Also i should mention that its always just one Formula shown the one that has the array place of Pagenumber.

use v-show instead of v-if if you mean toogling
or sometimes vue templates will not accept condition inside of it

Related

vuejs dynamic input collection with wrong values

I am dynamically adding inputs of type text to a vuex collection. It adds the input at specific index. It works good, no problem with that. The issue happens when I write some value in the input and then try to add a new one. The input value jumps to the newly added input.
Here is a simple code example: https://codesandbox.io/s/0yrzrw6120
Steps to reproduce:
There is a default input. You can add inputs below that, so:
Add a new input.
Write some value in the newly added input.
Add a new input again from the default button.
What I am expecting is a new input below default with no value in it, and it works but the value of the last input jumps to the newly added.
I understand is not a problem with the additions of items but the value in the inputs.

Getting value of previous selected item (dropDown)

When a user changes the selected item on a dropdown I need to get the PREVIOUS item selected,
EX:
dropdown items:
1) Questions
2) Jobs
3) Tags
4) Badges
User has #2 Selected and then changes to #4 -- How can I get the value of #2 when they change the selection?
Declare an instance variable in your form (WinForms) or window (WPF).
When a user selects an item:
Do what you want to do.
Save the current item index in the instance variable.
In step 1, you can now access the instance variable to get the previously selected item.
Declare a global variable that will contain the previous value.
When the user changes the selection in the combobox, set the variable to the currently selected value. Allow the selection to be changed. You now will have the previous value.
If you need to have the history of changes, then the global variable would be a collection. Then on changed event, add the current selection to the collection.
If your control is bound to data, there is no need to "Squirrel" the old value away, your data provider usually does this for you.
For example, if you are bound to a DataRow, this code will get the previous value.
? = [Your DataRow].item("[Your column name]",OrigialVersion)
This varies based on your data but ultimately, you could always re-query the database to get the original value as well.
Regardless of what you are bound too, if you ask the datasource for it's value during the Validating event of the control, it will have not changed yet so it will give you the old value, which you can then compare against the current selection.
Lastly, if you are not bound to data, I typically store the old value in the TAG property on the GotFocus event of the control. Then you can compare against that.
Hope this provides some other options that might help you, depending on your case.

Hidden model-bound values in view not getting passed to controller when populated manually

I'm using the KendoUI AutoComplete for a number of look-ups on a custom editor template that pop-ups off a grid for new rows and edits. The Kendo AutoComplete does have a DataTextField property and does not DataValueField property like a DropDownList would. So, I found I am able to get the Value of the selected item in the AutoComplete with a little Javascript and iterrogating the "dataItem" object in the select handler. And I put that value into a "SelectedID" field declared with #Html.HiddenFor(model => model.SelectedID) on the select event.
Now, when I do a save from the view and have a break point on my controller action that captures the incoming model, all those ID values where i set the value manually are empty/null/blank. I've checked the DO and have done "console.log" to read out the values of the hidden fields before the post and the values are populated. I've changed the datatypes (strings, guids, etc) and I've changed the Html Helper type as well from a HiddenFor to a EditorFor just to make sure the values are indeed there.
So i think this is a problem when the values of an element that are part of the model are populated in a "manual" fashion. The text of the AutoCompletes comes through if I bind that to a field on the model as well. Any date fields, checkboxes and free-form text fields come through as well. It seems it is just values of model bound fields where I set the values manually that don't make it over the "wire". Any thoughts? Solutions? I know the Selected Value is accessible ... it's just a matter of properly getting it into the "HiddenFor" fields.

Variable's value doesn't change in coffeescript when using onclick

I have the following Coffeescript code:
for name, data of statistics
row = document.createElement 'tr'
row.onclick = ->
alert name
However, when I compile and run it (in the context of a large webpage), it alerts the same name, no matter what row I click on. It seems to be remembering the variable, as if it's constant.
What am I doing wrong?
EDIT:
I've discovered the issue, but I'm not sure how to go about fixing it: Javascript/Coffeescript does not evaluate the 'name' variable until the end of the loop is reached.
The functions that you are defining (and assigning to the row's onclick attribute) all have access to the same variable outside that function (name). At the end of the loop, name has one value (the last item in the loop, as you mention), so each of the onclick functions alerts that value.
You can fix this by binding 'name' to a value that doesn't change. This question presents one solution. This question has some useful background that's worth reading.

How to use a session variable of one page to initialize another page's global variable in vb.net?

I have 2 web pages. In the first webpage I have a text box which takes an user input.The number of controls rendered in the second page is based on the user input in the first page.
I am storing the user input from the first page as a session variable
Session("NoOfControlsToGenerate") = TextBox1.Text
Now, I wish to use this session variable in the next page for initializing a global variable and what I tried to do is
Dim num_Invitees As Integer = CType(Session("NoOfControlsToGenerate"), Integer)
But this gives me a NullReferenceException.
Can someone please suggest me what exactly I should be doing in order to use the session variable to initialize a global variable and also why the session variable's value is null while using outside a function but works fine when used inside a function?Thanks in advance
Thank You
ASP.net makes passing such parameters deceptively easy. If you're posting back to the same page, you'll be able to simply read the value of the textbox, which will persist across the postback by default.
If you're posting to another page, you can use
CType(Page.PreviousPage.FindControl("YourTextBoxID"), TextBox).Text