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

options query do not replace option value in some situations #74

Closed
oncesk opened this issue Jul 24, 2015 · 4 comments · Fixed by #109
Closed

options query do not replace option value in some situations #74

oncesk opened this issue Jul 24, 2015 · 4 comments · Fixed by #109
Labels

Comments

@oncesk
Copy link

oncesk commented Jul 24, 2015

http://jsfiddle.net/3wagqq4h/2/

@oncesk oncesk changed the title options query do not replace option id in some situations options query do not replace option value in some situations Jul 24, 2015
@astoilkov astoilkov added the bug label Jul 25, 2015
@astoilkov
Copy link
Owner

Ok. I will fix this. There are couple of issues with the new reset implementation that I should go through. During that time you could use removeAll and then addMany instead.

@Kanaye
Copy link
Collaborator

Kanaye commented Oct 25, 2015

After thinking a bit about this issue I have a question:
Should we update the value of the select when the options get reseted / replaced?
Cause it can be missleading for the user if the browser shows that the selected value updated but the value in the application did not.
On the otherside it might be unexpected for the developer if the value get's updated with the reset.
To make more clear what I mean:

<select data-query="options(myOptions, {text:'text', value:'id'}).val(myVal)"></select>
var myOptions = blocks.observable([{
  id: '1', 
  text: 'Option 1'
}]);
var myVal = blocks.observable('1');

blocks.query({
   myOptions: myOptions,
   myVal: myVal
});


myOptions.reset([{
  id: '42',
  text: 'The answer to everything'
}]);

// Should 'myVal' now have the value 1 or 42 as the browser displays ? 
// Currently the value would be 1 (even if the dom would get updated correctly).

What do you think ?

@astoilkov
Copy link
Owner

I think the selected item shouldn't be one that does not exist. In this case after reseting the 1 doesn't exist so in my opinion we should just select the first item because this for me is the most correct value in scenario when the desired selected value is not present.

Did you understand what I want to say?

@Kanaye
Copy link
Collaborator

Kanaye commented Oct 26, 2015

Yes. I think I've got it.
I agree that the behavior is logical the best beside not removing the selected value, but that's on the dev building the app.

Kanaye pushed a commit to Kanaye/jsblocks that referenced this issue Oct 31, 2015
Update will check for selected value inside the updated collection.
Closes astoilkov#74.
Kanaye pushed a commit to Kanaye/jsblocks that referenced this issue Oct 31, 2015
Update will check for selected value inside the updated collection.
And update the value to the first 'data-rel="header"' or when provided
'caption' option or otherwise to the first value of the collection.
Closes astoilkov#74.
Kanaye pushed a commit to Kanaye/jsblocks that referenced this issue Nov 3, 2015
Update will check for selected value inside the updated collection.
And update the value to the first 'data-rel="header"' or when provided
'caption' option or otherwise to the first value of the collection.
Closes astoilkov#74.
astoilkov added a commit that referenced this issue Nov 4, 2015
Added update function to options-query fixes #74.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants