How to achieve Fix width and Below mentioned behavior.
- 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.
- A Dropdown with multiple select option where at least one option must be selected. (A kind of Mix of Radio and Check-box Behavior).
Hi rajulkansara,
-
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.
-
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.
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?
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 .
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.
I see.. Yes you have a valid purpose there. Anyway, does my suggestion to detect changes using $watch solve your problem?
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!'); });
Try this:
$scope.$watch( 'methodDropDownOptions' , function() {
alert( 'hey, I am changed!' );
}, true );
Yes it is working. Thanks.
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.