I am new to Vue and with the help of the docs and the Vue community on S.O. I have been making progress in learning how to make more complicated components.
This question is in regards to a custom select component, where the data for the selected option is correct, but the displayed HTML is not. I am providing a M.W.E.; however, this only occurs for me when the custom select component is nested through several other components.
I know this is a lot of code, so the M.W.E. is provided via Code Sandbox, where each component is in it's own file (making it easier to read).
Description of component
The component is meant to be an advanced data filter, that accepts an object that simulates a database, e.g. each key is a the "id" of its corresponding value ("record"). It then allows one to filter on the keys (properties / fields) of the record.
Thus we have the top-most component AdvancedFilterTable. This table allows the user to dynamically add and remove filters AdvancedFilterRows.
A filter row houses 5 simple components:
- logic: is the filter and / or (
AdvancedFilterSelectLogic) - function: what to be applied to the field (
AdvancedFilterSelectFunction) - property: which field to filter on (
AdvancedFilterSelectProperty) - conditional: what test to apply to each records afore set field (
AdvancedFilterSelectConditional) - value: the value to test in the conditional (
AdvancedFilterInput)
e.g.
{logic: 'and', function: 'identity', property: 'x', conditional: 'gt', value: 5}
The feature that I added which introduced the bug is dynamic options for AdvancedFilterSelectFunction and AdvancedFilterSelectConditional based on the type of AdvancedFilterSelectProperty.
e.g. if the selected property is x, where the corresponding value thereof is an array of numbers, then an option inAdvancedFilterSelectFunction should include "mean", "max", etc and AdvancedFilterSelectConditional should include "includes", "not includes", etc. However, if "mean" is selected (applying the function to the property changes its type) then the conditionals should change again (this time dropping "includes" and "not includes").
In the MWE provided, I have the following dummy data:
let records = {
a: { x: 1, y: "a string", z: [1, 2, 3, 4] },
b: { x: 2, y: "strange?", z: [1, 2, 4] },
c: { x: 3, y: "starts w", z: [1, 2, 3, 4] },
d: { x: 10, y: "some let", z: [1, 2, 4, 5, 6, 7, 8] },
e: { x: 2, y: "? qwerty", z: [1, 40] }
};
Where the type of x is number, y is string, and z in array number.
How to produce bug
open the mwe Code Sandbox

click the green plus icon to add a new filter
- click the property select and change x to z
Checking the components, all the corresponding data is set correctly. This is further emphasized as the function select and the conditional select have dynamically changes to include options specific to array type data.
Nonetheless, the select still shows 'x'. Trying to then select 'x' to reset the selection does not work as it is still selected to x...
The custom select's all pass their data through the different encapsulating components as outlined in Vue2: handling multi-child prop synchronization with models with the answer's fiddle: https://jsfiddle.net/SumNeuron/ejq86c73/9/
solution: https://61qky5y6mr.codesandbox.io/


