I am looking for a way to make my select into an autocomplete field. I know of angularJS directives that give you autocomplete functionality, but these don't allow the input name (what the user sees) and the input value (what the system uses) to be different. I need a select box, however, because the option name (that the user will see) and the option value (that the system will use) are different.
I know of such a plugin for jQuery, selectToAutocomplete, which is pretty neat and works well, but I would prefer to stay with AngularJS as much as possible. Is there an AngularJS alternative for jQuery selectToAutocomplete?
Angular UI ( http://angular-ui.github.io/bootstrap/ ) has a directive Typeahead which should fit your requirements. Look at that page for the 3rd example under Typeahead section with title Custom templates for results
Related
I've been experimenting with Symfony forms for some time. Without a doubt Symfony's FormType is a great feature which help create robust forms, especially with related entities (eg. ManyToMany, OneToMany etc.). The FormType makes my job a lot less complicated and easy when it comes to persistence. One of these case is the embedded forms, where u have multiple(lets say Category and Tag) entities with ManyToMany relation. Using FormType, I can create a 'Select dropdown' field using ChoiceType form field to choose category from, embed another CollectionType field with multiple 'text input' fields to accept multiple tagname, and finally a submit button. All I need is to add the cascade = {persist} option using annotations on the categoryname property of the Category entity and Wallah!
Now what if I wanted to create a single input field which can accept multiple tags, instead of having multiple input fields. Like this:
To do this I can create an <input> element using CollectionType form field, and then in my html.twig I can insert the javascript(jquery/AngularJS) dependency as attributes.
This can be done by using jquery Chosen or Select2 https://www.sitepoint.com/jquery-select-box-components-chosen-vs-select2/
or by using AngularJS ngTagsInput component http://mbenford.github.io/ngTagsInput/
Not just this particular case, I know that jquery delivers almost everything u want to do on the client side, and works good with Symfony, but I've been looking into AngularJS for some time now and it is undoubtedly true that it is further a step ahead of jquery or any other javascript framework. Thus my opinion is a little biased towards AngularJS.
The thing is, jquery(Chosen/Select2) uses <select> element and the AngularJS(ngTagsInput) uses custom <tags-input> element to display this field. Although with AngularJS I can make some elementary changes and convert the <tags-input> element to <div ngTagsInput> but I can't convert it to <input ngTagsInput> because the standard HTML<input> element has no closing tag, thus many features like auto-complete don't work. Customizing ngTagsInput & autoComplete directives (AngularJS)
Problem: For Symfony to persist the CollectionType field input in the standard way I need to use the <input> element to display the field.
Questions:
How do I make this work?
How compatible are Symfony and AngularJS? And is it recommended to use them together?
All help is appreciated.
Thanks in advance!
I have a form that i am trying to submit with angular JS
One of the field requires generation of an ethiopian calendar , so i am using an external javascript library to show this date - available here http://keith-wood.name/calendarsRef.html
To show the date picker one creates an input text as below:
<input type="text" id="ethiopianDOB" ng-model='Ethiopian'
And corresponding javascript
$( "#ethiopianDOB" ).calendarsPicker({
calendar: $.calendars.instance('ethiopian')
});
However this interferes with my ng-model binding and hence cannot access my variable in $scope (I reviewed the object on form submission and i have no item like $scope.Ethiopian
I am looking for ways to either
1. Retain the binding of the ng-model OR
2. Not require the javascript to instantiate the calendar OR
3. Improvement on my approach to this problem
Thanks
You should not mix JQuery and Angular if possible. Try to 'think in angular' instead of falling back on JQuery.
Here is a great post about this topic: "Thinking in AngularJS" if I have a jQuery background?
That being said, you should try to replace the JQuery calendar with an angular directive such as the datepicker from Angular UI Bootstrap. I don't know if they have an Ethopian calendar but you could always build your own.
This would fix your issue.
Hope this helps.
Currently I am using Jquery Chosen Plugin in order to search the values written inside a search box and it works very well in case I want to search on the basis of the text written inside the option tag. i.e. as shown in the figure:
But what I want to achieve is search on the multiple basis i.e. on the basis of the text written inside the option tag as well as the data attributes of the option tag i.e.
For example in the above figure I may be able to search Debitors either by typing Debitors directly or by typing the data-phone's value i.e.0321-111111. I've searched the chosen plugin's documentation for the possibility to search on the basis of multiple values but, as much as I know, there wasn't any functionality provided by it.
Now what I'd like to ask is, Is there any jQuery plugin providing this multisearch functionality that you may know of?
Thanks.
Finally, I found Select2 Jquery plugin that allows the custom matcher for the searching. i.e. You can define whatever you want plugin's search to search.
I want to create a combobox with a hierarchical list of items. I need to be able to select the parent items as well as the children individually. I also need to be able to provide typeahead capabilities for this combobox.
For example, I want to make a combobox with this data in JS:
Canada
--Ontario
--Quebec
USA
--Massachusetts
--Ohio
--Texas
From this dropdown I want to be able to select any of the provinces/states individually. I also want to be able to select "Canada" without selecting it's children.
I've tried Select2 and have been digging around JQuery UI to see if it is possible, but so far I can't quite achieve the behaviour I need. I'm writing this page using bootstrap, but the given typeahead in boostrap doesn't seem to work with comboboxes at all (that I can see).
You can use Chosen javascript plugin to achieve this.
http://harvesthq.github.com/chosen/
You can store custom JS objects for each typeahead result so that it can displays and store more than just a string (a type, or ID for example). Using that would let you have different logic for country vs province/state. Here's an example of doing so:
https://github.com/twbs/bootstrap/pull/3682
So in the updater function, you could have logic based on your custom object to determine whether it's a parent or child that was clicked.
As far as making the parent look different than the child, I haven't used it myself, but there is a templating system in bootstrap. Check out this link for an example:
https://github.com/twbs/bootstrap/issues/2441
You could likely use this to differentiate the parent and child look and feel.
I'm just hoping to get an idea on how to go about creating the following functionality on a screen. I've been using webforms in the past so I felt the need to get over it and start using MVC before I get left behid, so to speak.. thus the project is in Asp.NET MVC, (& JQUERY, but have been getting more comfortable with it lately), so I feel it should be do-able at this point)
I basically want an autocomplete. The employee no textbox should act as input, and as the user types, the items below should render/be visible & update, something to that effect. I'm id like to colour code them by relevancy/or by time.
I think I've got the following problems/questions.
1.) How would I submit without a button click.
and my controller would return a JSON result (I'm assuming would be the best route)
2.) Update/Render my results without redrawing/posting the page
3.) Applying the colours (but its minor at this stage)
I know its asking a lot. So thank you in advance.
Any links of tuts would be appreciated as well.
UPDATE
I just relized that how google's search is working would be a perfect example. Autocomplete on the textbox & results start displaying as you type
As your using jQuery and MVC3 the default MVC3 template aslo contains jQuery UI with has an autocomplete widget that is easily adaptable to what your after.
http://jqueryui.com/demos/autocomplete/#remote
Have you considered usign jQuery UI Autocomplete?
It seems to be valid for all the points that you mentioned.
You can check it out here:
jQuery UI Autocomplete