angular-multi-select icon indicating copy to clipboard operation
angular-multi-select copied to clipboard

How to achieve Fix width and Below mentioned behavior.

Open rajulkansara opened this issue 12 years ago • 9 comments

  1. How to achieve fix width( in the declaration tag for ex. width = 200px) of dropdown no matter what is selected. If selected options text width is big, it will show ... after truncated text. If it is small it would show empty space.
  2. A Dropdown with multiple select option where at least one option must be selected. (A kind of Mix of Radio and Check-box Behavior).

rajulkansara avatar Jun 17 '14 19:06 rajulkansara

Hi rajulkansara,

  1. Not planning to do this, but you can get (almost) similar result by combining the max-labels attribute and set the button width in the CSS.

  2. Validate your model before you process the data. For example, before you save your form, you can loop over your input-model and check if at least one of the model's tick-property is true.

On Wed, Jun 18, 2014 at 3:42 AM, rajulkansara [email protected] wrote:

How to achieve fix width of dropdown no matter what is selected. If selected options text width is big, it will show ... after truncated text. If it is small it would show empty space. 2.

A Dropdown with multiple select option where at least one option must be selected. (A kind of Mix of Radio and Check-box Behavior)

— Reply to this email directly or view it on GitHub https://github.com/isteven/angular-multi-select/issues/22.

isteven avatar Jun 18 '14 01:06 isteven

For Number 2, i understood what you are advising. This has gave me hint that everytime any option is clicked i listen to to those changes and according i can achive alteast one option is selcted. But i did not find and event that is fire on every time i clicked on option. Do onChange will fire on model? or Any other specific event would fire on selecting or deselecting option?

rajulkansara avatar Jun 18 '14 13:06 rajulkansara

There's no onChange event because you can simply use $watch in your controller to watch changes in the input model $scope variable. The directive will update the input model as you select / deselect a checkbox.

But the question is, why do you need to validate things on change? You can always validate before you save your form. On Jun 18, 2014 9:51 PM, "rajulkansara" [email protected] wrote:

For Number 2, i understood what you are advising. This has gave me hint that everytime any option is clicked i listen to to those changes and according i can achive alteast one option is selcted. But i did not find and event that is fire on every time i clicked on option. Do onChange will fire on model? or Any other specific event would fire on selecting or deselecting option?

— Reply to this email directly or view it on GitHub https://github.com/isteven/angular-multi-select/issues/22#issuecomment-46437733 .

isteven avatar Jun 18 '14 14:06 isteven

It is a UX. Validation on submit would waste my few click rather i want user to realize that he would have to have select at least one check box.

rajulkansara avatar Jun 18 '14 15:06 rajulkansara

I see.. Yes you have a valid purpose there. Anyway, does my suggestion to detect changes using $watch solve your problem?

isteven avatar Jun 18 '14 16:06 isteven

I tried watch and watchcollection both in my controller. None of them worked. On Checking and Unchecking i am not getting below alert. Let me know where i am wrong.

HTML

Method:

-----Controller $scope.methodDropDownOptions = [ { name: "Option1", ticked: true },{ name: "Option2", ticked: false }, { name: "Option3", ticked: false }

$scope.$watchCollection('methodDropDownOptions', function() { alert('hey, I am changed!'); });

rajulkansara avatar Jun 18 '14 18:06 rajulkansara

Try this:

$scope.$watch( 'methodDropDownOptions' , function() {
    alert( 'hey, I am changed!' );
}, true );

isteven avatar Jun 18 '14 23:06 isteven

Yes it is working. Thanks.

rajulkansara avatar Jun 19 '14 01:06 rajulkansara

You're welcome, glad the directive works for you.

I'll consider that onChange() callback ( or onItemClick() perhaps ).. Looks like it'll be useful for some, as using $watch with objectEquality == true on complex / big object actually has an adverse memory and performance implications - as stated in AngularJS website.

I'm closing this issue now. Feel free to open a new one anytime. Cheers.

isteven avatar Jun 19 '14 02:06 isteven