Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiselect not updating when linked array changes #450

Closed
johan-ohrn opened this issue Sep 15, 2020 · 10 comments
Closed

multiselect not updating when linked array changes #450

johan-ohrn opened this issue Sep 15, 2020 · 10 comments

Comments

@johan-ohrn
Copy link

Please have a look at this fiddle. (code below)
Notice that the select element without the copy converter does not update.

I found that the select element does not update it's selected values when you observably modify the selectedValues array.

I followed the code flow and found this line in jquery.views.js:
623: if (change = change || targetVal !== sourceValue) {
As a workaround I realized I can just create a converter that copies the array so that targetVal and sourceValue are different array instances.
It works but it's not very obvious.

html:
<div id="ph"></div>

js:
$.views.converters({
  copy: function(arr){return arr.slice();}
})

var vm = {
  selectedValues: ["value2"]
};

$.templates("\
	with copy converter \
  <select multiple data-link='{copy:selectedValues:}'>	\
    <option value='value1'>1</option>	\
    <option value='value2'>2</option>	\
  </select>		\
  without copy converter \
  <select multiple data-link='selectedValues'>	\
    <option value='value1'>1</option>	\
    <option value='value2'>2</option>	\
  </select>		\
").link("#ph", vm);


setTimeout(function() {
  console.log("blah")
	$.observable(vm.selectedValues).refresh(["value1"]);
},1000)
@BorisMoore
Copy link
Owner

Thanks Johan. I'll look into it...

@BorisMoore
Copy link
Owner

Hi Johan,
It's been a long time and I did in fact find a fix for your issue above, but also discovered some slightly related problems with the checkboxgroup tag. I have been working towards a new update which will include your the fix for your issue. But it's taking a while.... If you can wait for your fix, that's good, but if you would hope to get it sooner, let me know and I'll probably create an intermediate update with just your fix...

@johan-ohrn
Copy link
Author

Hi,
Good to hear. We will wait for the fix since we have a workaround for the problem.
Thanks

@BorisMoore
Copy link
Owner

This update should fix your issue, along with a number of other small issues I found, particularly concerning <select>, multiselect, and {{checkboxgroup}}, (and some elsewhere...)

jsviews8e.zip

Let me know if it works for you...
Thanks!

@BorisMoore
Copy link
Owner

Update - I am checking another possible issue, so probably better to wait before testing jsviews8e, above. I'll keep you posted if there is a corrected version coming...

@BorisMoore
Copy link
Owner

OK, I think this update is good. Let me know if you find any issues in your environment'
Thanks!

jsviews8f.zip

@BorisMoore
Copy link
Owner

I'm moving towards publishing the above a v1.0.8. Of course, if you do find an issue before I actually publish, then I'll put it on hold, but I am pretty sure that for known issues it is good...

@johan-ohrn
Copy link
Author

I probably won't be able to test it in the coming days. I'm stuck with some major pita I must attend to first. I'll write back here though when I have tried it. I'm sure it will work tho :)

@BorisMoore
Copy link
Owner

Thanks Johan, yes, that's fine. I'll go ahead with what we have. Worst case we'll need a v1.0.9 subsequently. (Which at some point will happen anyway...)
Thanks for letting me know status so rapidly...!

@BorisMoore BorisMoore added the Bug label Oct 25, 2020
BorisMoore added a commit to BorisMoore/jsviews.com that referenced this issue Oct 25, 2020
Feature improvements:
  - Improvements (and associated bug fixes) when converters return arrays.
    With minor breakng change for some advanced scenarios:

    Converters which return arrays now have an improved heuristic behavior
    to determine whether to return the array (retArray) as value for the
    first argument, or as an array of values for multiple bindTo/bindFrom
    targets.
    (If bindTo/bindFrom is an array of length l, l > 1 and the converter
    is returning an array retArray of length l, then treat retArray as an
    array of values for the multiple targets bindTo/bindFrom targets)
    In addition the heurisic default behavior can be overidden by setting
    retArray.arg0 = true/false.

    See http://jsviews.com/#tagoptions@bindto
    and http://jsviews.com/#hierarchypatterns@picker-multi

Several bug fixes, and code improvements, particularly for data-linked
<select> tags (including multiselect), and {{checkboxgroup}} tags:

  - BorisMoore/jsviews#450
    multiiselect not updating when linked array changes

  - BorisMoore/jsviews#449
    If the selected value of a data-linked <select> is set prior to adding
    options, selection is not always established correctly

Additional small corrections or improvements to documentation, and some
additional unit tests...
BorisMoore added a commit that referenced this issue Oct 25, 2020
Feature improvements:
  - Improvements (and associated bug fixes) when converters return arrays.
    With minor breakng change for some advanced scenarios:

    Converters which return arrays now have an improved heuristic behavior
    to determine whether to return the array (retArray) as value for the
    first argument, or as an array of values for multiple bindTo/bindFrom
    targets.
    (If bindTo/bindFrom is an array of length l, l > 1 and the converter
    is returning an array retArray of length l, then treat retArray as an
    array of values for the multiple targets bindTo/bindFrom targets)
    In addition the heurisic default behavior can be overidden by setting
    retArray.arg0 = true/false.

    See http://jsviews.com/#tagoptions@bindto
    and http://jsviews.com/#hierarchypatterns@picker-multi

Several bug fixes, and code improvements, particularly for data-linked
<select> tags (including multiselect), and {{checkboxgroup}} tags:

  - #450
    multiiselect not updating when linked array changes

  - #449
    If the selected value of a data-linked <select> is set prior to adding
    options, selection is not always established correctly

Additional small corrections or improvements to documentation, and some
additional unit tests...
@BorisMoore
Copy link
Owner

BorisMoore commented Oct 25, 2020

Resolved in v1.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants