Skip to content

ui-select or select2 with angular-schema-form-dynamic-select? #15

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

Closed
subhendupsingh opened this issue May 12, 2015 · 89 comments
Closed

Comments

@subhendupsingh
Copy link

How can I implement ui-select or select2 with angular-schema-form-dynamic-select, I see that select behaviour here is applied to a button, i want it to be a dropdown like ui-select or select 2.

@subhendupsingh subhendupsingh changed the title How can I implement ui-select or select2 with angular-schema-form-dynamic-select? ui-select or select2 with angular-schema-form-dynamic-select? May 12, 2015
@nicklasb
Copy link
Member

I don't know about select2 for ASF, while I have considered also implementing ui-select, it is not currently in the pipeline.
I would recommend that you look at angular-schema-form-uiselect instead.

@nicklasb
Copy link
Member

Just out of interest, why does it matter if it is a button? Or something else?

@nicklasb
Copy link
Member

Oh, I realized now what you meant.

@subhendupsingh
Copy link
Author

Angular schema form uiselect and dynamic select won't work together because
of the button implementation. What can I do as a workaround?
On May 13, 2015 5:44 AM, "Nicklas Börjesson" [email protected]
wrote:

Oh, I realized now what you meant.


Reply to this email directly or view it on GitHub
#15 (comment)
.

@nicklasb
Copy link
Member

That sounds strange. In what way does the usage of buttons in ASFDS and the use of div:s in ui-select conflict? I am sorry if I am a bit daft, but I don't get it?

@nicklasb
Copy link
Member

The reason it is implemented that way in ASFDS is because that is the way the angular-strap select is invoked: http://mgcrea.github.io/angular-strap/#/selects-usage

I would be strange if two different classes of HTML elements interacted like that.

In what way doesn't it work?

@nicklasb
Copy link
Member

Ok, so now I went ahead and actually added basic support for ui-select in the develop branch, it turned out to be not that hard, I mixed stuff from the chengz and stevehu-forks and reworket it to work in the stuff in this component.

There are some filter related errors to iron out, but in general, it seems to work pretty well.

@nicklasb
Copy link
Member

If you want to try out that, just 'bower update angular-schema-form-dynamic-select#develop', unless you work against the git repo directly.

@subhendupsingh
Copy link
Author

That's really cool. Thumbs up, I will give it a try and let you know.
On May 13, 2015 6:37 PM, "Nicklas Börjesson" [email protected]
wrote:

If you want to try out that, just 'bower update
angular-schema-form-dynamic-select#develop', unless you work against the
git repo directly.


Reply to this email directly or view it on GitHub
#15 (comment)
.

@subhendupsingh
Copy link
Author

Can you please show some code how to apply ui-select to ASFDS, i am new to angular js, i updated the installed the devstream but dont know how to use ui-select.

@nicklasb
Copy link
Member

First, update again.

Then, the index.html in the root of the library is the demo application. The angular example resides in app.js, I have added two UI-selects there. The second doesn't work properly yet.

@nicklasb
Copy link
Member

Remember to use #develop, this is only in that branch.

@subhendupsingh
Copy link
Author

Thanks! :)

@subhendupsingh
Copy link
Author

I am getting

Cannot GET /directives/decorators/bootstrap/uiselect/uiselect.html

@nicklasb
Copy link
Member

Are you sure you are using the angular-schema-form-dynamic-select.js in the root, and not the file in /src?

@nicklasb
Copy link
Member

Because the template caches should be populated with that content.

@subhendupsingh
Copy link
Author

Yes i am using js in the root

../bower_components/angular-schema-form-dynamic-select/angular-schema-form-dynamic-select.min.js

@subhendupsingh
Copy link
Author

I will have to use ../bower_components/angular-schema-form-dynamic-select/angular-schema-form-dynamic-select.js

@subhendupsingh
Copy link
Author

Getting this now:

{{form.title}}
{{select_model.selected.name}} {{(select_model.selected.isTag===true ? form.options.taggingLabel : '')}}
{{select_model.selected.name}} {{(select_model.selected.isTag===true ? form.options.taggingLabel : '')}}

@nicklasb
Copy link
Member

Ok, I just realized it will not work like that.
Instead you need to git clone the repository to get all the dependencies satisfied in the right place.
Just follow the documentation:
https://github.com/OptimalBPM/angular-schema-form-dynamic-select#example

Then checkout the develop branch, and add the remaining dependencies for ui-select. I have not decided what will be included in the library, but just look in the index.html, and check so that all those scripts and css:es are available.

@nicklasb
Copy link
Member

These additional libraries should get you going:

underscore
angular-underscore
angular-ui-utils
angular-translate
angular-ui-select

@nicklasb
Copy link
Member

I will add those I deem relevant to the dependencies in the bower.json after I have cleared up what is actually needed.

@subhendupsingh
Copy link
Author

Included all the dependencies, now getting

Error: [$injector:unpr] Unknown provider: highlightFilterProvider <- highlightFilter

@subhendupsingh
Copy link
Author

I have included ngSanitize too. Any idea about this?

@subhendupsingh
Copy link
Author

I was getting /directives/decorators/bootstrap/uiselect/uiselect.html, so i made the directory structure in my app and put uiselect.html there, then i started getting

Error: [$injector:unpr] Unknown provider: highlightFilterProvider <- highlightFilter

@nicklasb
Copy link
Member

Oh, sorry, you need to in stall angular-ui-utils:

bower install angular-ui-utils

@nicklasb
Copy link
Member

Yes, angular-sanitize is needed too, basically, you can see what dependencies there are in the index.html. If they are all satisfied, it should work.

@nicklasb
Copy link
Member

I do suspect, however, that some of these dependencies are not completely necessary, however I am not sure how strict I should be about that.

@nicklasb
Copy link
Member

@subhendupsingh , if you do a git pull now, the uimultiselect works as well. There was a bug in the original implementation.

@nicklasb
Copy link
Member

Well, that part haven't changed, as far as I can see. I have not changed any of the callback in my example.
Also, you are putting a .then on the documentsData-call. Which is not correct if it isn't a promise.
It seems pretty reasonable that something is undefined when that is the case.

@subhendupsingh
Copy link
Author

Used the method you suggested with asyncCallback, still getting:

Cannot read property 'forEach' of undefined

@nicklasb
Copy link
Member

How does your code look now?

@subhendupsingh
Copy link
Author

actually it is $http.post service and i have read somewhere that $http returns promise by default. Thats the reason i used it that way.

@nicklasb
Copy link
Member

The last thing I didn't understand.

@subhendupsingh
Copy link
Author

form[i].options = {
"asyncCallback": "getCurrency"
};

and

$scope.getCurrency=function(options){
var defer=$q.defer();
DocumentsDataService.documentsData("CURRENCY",null,null, function(result){
var currencyArray = []
if(result!=null && result!=''){
for(i in result){
currencyArray.push({
"value": result[i].isocode,
"name": result[i].name
});
}
}
console.log(currencyArray);
defer.resolve(currencyArray);
});
return defer.promise;
};

@nicklasb
Copy link
Member

Well, the defer.resolve must be inside the callback, or it'll never be called:

$scope.getCurrency=function(options){
    var defer=$q.defer();
    DocumentsDataService.documentsData("CURRENCY",null,null, function(result){
        var currencyArray = [];
        if(result!=null && result!=''){
            for(i in result){
                currencyArray.push({
                    "value": result[i].isocode,
                    "name": result[i].name
                }
             }
        }
        console.log(currencyArray);
        defer.resolve(currencyArray);
    });


    return defer.promise;
    };

Also, I cannot test this code, it is just a suggestion.

@nicklasb
Copy link
Member

Also, do not look at e-mails, look here at github, as I (and most others) often edit messages for a short while after posting
.

@subhendupsingh
Copy link
Author

This is the code from my service do i need to return a promise from here?

if(mode=='CURRENCY'){
                    endpoint=API_CURRENCY_ENDPOINT;
                    return $http({method: "GET",url: endpoint})
                        .success(function(result){
                            //console.log(result);
                            loginCb(result);
                        })
                        .error(function(result){
                            //console.log(result.data);
                            loginCb(result);
                        });
                }

@nicklasb
Copy link
Member

You are mixing two things that should not be mixed here, synchronous callbacks and asynchronous promises.

I would recommend that you do not use a callback, and do not implement the .success and .error. (especially as the error is ignored)
Just return the $http-promise to $scope.getCurrency and implement it like this.

$scope.getCurrency=function(options){
    var defer=$q.defer();
    DocumentsDataService.documentsData("CURRENCY",null,null).then( function(result){
        var currencyArray = [];
        if(result!=null && result!=''){
            for(i in result){
                currencyArray.push({
                    "value": result[i].isocode,
                    "name": result[i].name
                }
             }
        }
        console.log(currencyArray);
        defer.resolve(currencyArray);
    });


    return defer.promise;
    };

If you someday feel you need control in DocumentsDataService.documentsData, like for caching and to on, implement that as well asynchronously, it is the way it is done in javascript.

If you want to make it really simple, use the options.httpGet shorthand combined with the remapping functionality, actually the example is exactly your use case:
https://github.com/OptimalBPM/angular-schema-form-dynamic-select#property-mapping

@nicklasb
Copy link
Member

Ok, I have found that there are several bugs in the current version of the ui-select component that affect this component, and they appear when I set an initial value:

  1. This has been resolved but hasn't been released: Issue: TypeError: Cannot read property 'length' of undefined at ctrl.getPlaceholder  angular-ui/ui-select#519
    TypeError: Cannot read property 'indexOf' of undefined
  2. I don't really understand the proposed solution here: Async data tons of errors in console angular-ui/ui-select#380

@nicklasb
Copy link
Member

Hold on, I am rewriting the implementation to make it simpler to understand.
It seems that the library I used as a baseline for my implementation does a lot of things that isn't necessary anymore, and that is probably part of the problem.

@subhendupsingh
Copy link
Author

That would be great.
On May 18, 2015 3:13 PM, "Nicklas Börjesson" [email protected]
wrote:

Hold on, I am rewriting the implementation to make it simpler to
understand.
It seems that the library I used as a baseline for my implementation does
a lot of things that isn't necessary anymore, and that is probably part
of the problem.


Reply to this email directly or view it on GitHub
#15 (comment)
.

@nicklasb
Copy link
Member

Well, I have been swearing over this for two days now, so this is the only way for me to avoid coming back as an insect, karma-speaking. :-)

@nicklasb
Copy link
Member

I hit some issues, and to not have to basically redo what the base implementation did, I asked them a question about it instead:
angular-ui/ui-select#934

@nicklasb
Copy link
Member

I have now released 0.9.1. It fixes some of these issues. However UI-select does not work completely yet, it is possible to select multiple identical items in some cases and so on. But perhaps you can use that for now.

@subhendupsingh
Copy link
Author

What about callbacks? Are they working now?
On May 18, 2015 6:46 PM, "Nicklas Börjesson" [email protected]
wrote:

I have now release 0.9.1. It fixes some of these issues. However UI-select
does not work completely yet, it is possible to select multiple identical
items in some cases and so on. But perhaps you can use that for now.


Reply to this email directly or view it on GitHub
#15 (comment)
.

@subhendupsingh
Copy link
Author

Great i just saw in the examples, you have implemented uiselect with callback.

@nicklasb
Copy link
Member

Well, there was no problem with callbacks per se, but there was a problem with strapselect that had options, but not "options.multiple = true".

@subhendupsingh
Copy link
Author

Awesome!

@subhendupsingh
Copy link
Author

This is weird but i am still getting

[ui.select:items] Expected an array but got '{}'.

@nicklasb
Copy link
Member

What, from getCurrency?
How does it look now?

@subhendupsingh
Copy link
Author

To test i am just returning an array object:

$scope.getCurrency=function(options){
                
                var arr=[{"value":"INR","name":"Indian Rupee"}];
         
            return arr;
        }

@nicklasb
Copy link
Member

And the form part?

@subhendupsingh
Copy link
Author

yes i have used plain callback.

form[i].type = "uiselect";
                   
                    form[i].options = {
                        "callback": "getCurrency"
                    };

@nicklasb
Copy link
Member

From where do you get the error? In what source line is it?
Can you trace into the code?

This would be one of those cases where a plnkr.co-example would be very helpful.

That is actually the normal way to handle stuff like this on github these days, it is much faster to debug a running example that exhibits the behavior.

Also, I must be going to bed now. Wait, it looks like you are in Delhi or something, you should too. :-)

@subhendupsingh
Copy link
Author

your "plain callback" thing got it working 👍

$scope.getCurrency=function(options){
            var arr=[];
            DocumentsDataService.documentsData("CURRENCY",null,null,function(result) {
                if (result != null && result != '') {
                    for (i in result) {
                        arr.push({
                            "value": result[i].isocode,
                            "name": result[i].name
                        })
                    }
                }
            });
            return arr;
        }

Thank you so much for all the help and patience and yes I am in Delhi and will happily go to bed now. Have good night!!

@nicklasb
Copy link
Member

So DocumentsDataService.documentsData was synchronous after all, and didn't return a promise then?
You had a '.then(function(){...' in the earlier example, so I was certain it did.

No problem, thanks for all the feedback, if it weren't for that, it would have been more difficult.
Your tries
And I wouldn't have implemented ui-select if you hadn't gotten me to rethink that position.

Good night!

@nicklasb
Copy link
Member

Closing this now, I'll monitor the success of the ui-select-issue so that can be brought up to 100%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants