question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple checked options

See original GitHub issue

Hey.

I am using multiple-options. Is there a way to pre-set/check options (option.checked="true")?

User will pick som options, save selected data, and then late view the list again with the saved data already selected. (I only save the value, not the object/name. So I rebuild the list with .checked=true myself).

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
klodhacommented, Sep 26, 2017

Encountered this issue and after lot of debugging finally found this issue.

Based on @kotromeo comment, I found the exact location where I can put missing code, and following is what I put. Of course, it hard coded for my case assumes that all options are Objects and each object has ID field which in common. Someone may take this approach and provide a proper fix, so just sharing here.

function initialOptionsSetup(nv) {
	nv = nv || [];
	if (!multiple) 
	{
		allOptions = angular.copy(nv);
		scope.options = angular.copy(nv);
	} 
	else 
	{
		allOptions = nv.map(function (item, idx) {
			return [idx, angular.copy(item)];
		});
    
	    //This is to get values for ng-model 
	    //and mark them checked. passed data must be OBJECT with ID being key
	    //for this snippet to work  @KML@
	    var presetValues = ngModelController.$viewValue;

    	angular.forEach(allOptions, function(option){
    		for(var i = 0; i < presetValues.length; i++)
			{
				if(presetValues[i].id == option[1].id)
				{
            		scope.isChecked[option[0]] = true;
                	break;
				}
			}
		});
		scope.options = angular.copy(allOptions);
		scope.setValues();
	}
}
2reactions
kotromeocommented, Jul 23, 2017

i think there could be simple code fix to make values selected depend on model. this code example helpm me to make all values checked http://take.ms/XSg8q

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkboxes - The complete HTML5 tutorial
Checkboxes. Using checkboxes is a good option when you want to give your visitors the option to choose several items from a group...
Read more >
Multi-select Check Box List or Checkbox Dropdown with ...
Check Box list is useful to allow the user to select multiple options in a select box. But in this case, multiple options...
Read more >
Checkbox to select multiple choice inside a HTML Form ...
i.e, a checkbox can be in one of the two states, either checked or unchecked. From a group of checkboxs user can select...
Read more >
<input type="checkbox"> - HTML: HyperText Markup Language
Where multiple controls exist, radio buttons allow one to be selected out of them all, whereas checkboxes allow multiple values to be ...
Read more >
HTML select multiple Attribute
The multiple attribute is a boolean attribute. When present, it specifies that multiple options can be selected at once. Selecting multiple options vary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found