Using tokeninput plugin in datatables editor
Using tokeninput plugin in datatables editor
Hello,
There an autocomplete plugin called "Tokeninput" is like "Jquery Autocomplete", but easier in customization. This plugin work with any input field. My question is can I use it with editor or need special plugin like "Jquery Autocomplete".
Thanks in advance
Replies
I haven't seen that library before - it looks good (although the demo doesn't appear to work on an iPad). To be able to use it inside Editor, you need a field type plug-in which serves as an integration between Editor and the external library. It allows Editor to do things like initialise the field, get and set values, etc.
Allan
Thanks Allan,
I have tried to create custom field type for tokeninput" plugin it suppose to create some lits dynamically, but it doesn't. I have implemented this plugin with normal html and it works fine. Here is my code for Create function for custom field:
In normal HTML this plug-in need simple input type text as:
And the following is JS code for it:
So could you please see what is wrong with our code.
Regards
Looks like TokenInput needs the element to be in the document before it can be initialized:
Working example: http://live.datatables.net/kizozuxu/1/edit . The styling is rubbish, but perhaps you have some styles for TokenInput. It doesn't appear to have any of its own.
Allan
Hi,
Thanks alot Allan.
I have applied the code and it worked, but there are some bugs in it.
1- When open the form (New or Edit) several times the input field will repeat in the form as opened (eg. form opened 5 times, the input field will repeat 5 times ) as
I solved this bug by adding this function to the "Create" method as:
2- In Edit form the input field appear empty. Also, if I create new row and after that I edit another row the input field will get the values of the inserted row. NOT SOLVED YET
3- There are several function work with this libirary such as "PrevetDuplicate", but it doesn't work with editor. NOT SOLVED YET
Regards
Hello Allan,
I have add the close function and tokeninput CSS to the example you provided
Herelive.datatables.net/qaragofo/1/edit
Regards
Here is a bit of an update: http://live.datatables.net/qaragofo/2/edit . I've got it doing an init only once - checking a variable on open or set - whichever comes first will run it.
It also looks like we can't just use
$().val()
to get and set the value - needs the tokenInput plug-in's API. I presume that you've used it before (?) so you'll be far more expert in it that me just looking at the documentation for the first time, but I've tried a little bit with the get and set functions. I'm not sure it is right, and I think the correct answer will actually depend upon the structure of your data (e.g. name / id pairs?). But hopefully that is a useful starting point.Allan
Thanks alot Allan