-
Notifications
You must be signed in to change notification settings - Fork 1.8k
setting chosen property of selected object as ngModel instead of the whole object #68
Comments
Currently that shows: |
No, I'm quite sure I only want the email in my model. It may be that I didn't state it clear enough. Let's rephrase: I'd like to modify a single property of my object and that property holds the user identifier, which is the email in my case. On the other hand I want for the user to be able go get rich suggestions with the user name (or maybe other data as well). I of course can proxy this in my controller by creating some $scope property (as it is done in the demo: $scope.person) and after this property gets changed update my actual model but it's ui-select job in my opinion |
Ah, OK. I see what you mean. Looking through the code ui-select uses @repo Owner/Contributors: Can I have a go at changing the ng-repeat expression into the select logic from angular? |
@SimeonC could you open a PR and we start checking implications of this. Anyway I do see a real use case here |
@dimirc Please take a look at this Plunker, sample for setting ID. |
@j-hogue I just checked it and seams that it could work. Can you do a PR with the changes to review it better? |
Realised that there's a much simpler way of doing this that I discovered during some of my other work with custom templates. Plunkr: http://plnkr.co/edit/svthAFvAmW7D0m8DYuA2?p=preview I haven't fully tested this but AFAIK it should work as a workaround for @jrencz original use case. app.directive('uiSelectField', function() {
return {
restrict: 'A',
require: ['uiSelect', 'ngModel'],
link: function(scope, element, attrs, ctrls) {
var $select, ngModel;
$select = ctrls[0];
ngModel = ctrls[1];
return ngModel.$parsers.push(function(value) {
if(value[attrs.uiSelectField]) return value[attrs.uiSelectField];
else return value;
});
}
};
}); It might take me quite some time before I can get back around to doing the aforementioned PR I talked about. |
That would work, the regex would be: I've got some time now if you want me to run up a PR? |
Yea that looks about what I was going to do, I'll go make comments on that issue. |
I find this feature very cool. I think should be well documented. |
I'd like to ask if the module already is capable of the following and I just haven't found how or is it not yet possible:
Referring to the demo: I'd like for the module to be able to set only the email of the selected person as ngModel value, not the whole object (email, name, age) as it does now.
As I inspected the code it seems to be impossible looking at the line 62:
and the way
ctrl.select
is used for both keyboard and pointerWhat I'd like to propose is something closer to the ngOptions
select as label for value in array
syntax in the native angular select butlabel
is not used in this case anyway since it's displayed using the template that is transcluded - so let's name itproperty as value in array
. Example:The text was updated successfully, but these errors were encountered: