Load LDAP datas to editor Input
Load LDAP datas to editor Input
Hello,
i have a table with 3 simple columns: ID, Name and eMail. In the datatables editor i have only the input field "id". After entering the "id", i want to ask the LDAP if the "id" is right. If it's right, the fields "name" and "email" should be automatically fill out by the LDAP.
If the "id" doesn't exists, the editor has to show an error messages (i.e. "Wrong ID") and waits for a new id or a cancelation.
How can i make this with datatables editor?
Thanks a lot for any help.
Additional Info:
In an earlier version of my project i did this, with an own input page with php and ajax (to get the LDAP datas). But in a new version of my project i want to do everything by datatables with the editor extension. It's easier for the users to use only one style of input forms.
This question has an accepted answers - jump to answer
Answers
Hi @dg_datatables ,
You could use
dependent()
to validate the additional data, or post the error with the-e-api field().error()
for the ID.Cheers,
Colin
Hi Colin,
thank you very much for your fast support.
I'll give the
depent()
a try. I will answer again after my testing.Regards
Christian
I did not manage to get a result with
depent()
. I tried thepreSubmit()
. If i understand it right, this will be fired after the input of the form. This seems for me more logical to use this api. I tried this:pdata.data[ key ]['login'] is the entered NT-Login
pdata.data[ key ]['tname'] is the field for the displayName
pdata.data[ key ]['login'] is send via ajax to a small php file. This asked the LDAP and send back the displayName of the NT-Login. This works perfectly, but datatables does not take the feedback from Ajax.
If i write alert(axdata), i see the response from ajax.
If i write pdata.data[ key ][ 'tname' ] = 'foo'; then 'foo' is shown as the displayname in datatables. So i can manipulate this field, but why does it not take the ajax response?
I'm sorry but i can't show the webpage, because it's in an intranet and has no public access.
dependent()
is the way I would suggest doing this as well. Can you show me the code you tried for it please?The problem with using
preSubmit
here is that it does not expect an async result. Rather it will just immediately submit the form, without waiting for your Ajax response!Allan
Uhhh no async!
I will see if i will find my
dependent()
tries, otherwise i will give it a new try.Ok, i tried this one:
My problem is, that nothing is send to the ajax file. The ajax file responses with "not found" and then "not found" is entered in the correct datatables field (tname). Why will the value of the field "login" not send to the ajax?
Have i to send it manually? i.e. data: { login: login }
I played a little around and changed the code to the following:
Now Ajax received the values and response the correct datas (Yewha!). But datatables doesn't accept it. This line editor.field('tname').val( axdata ); is now my problem. 'axdata' is correct filled with the string (displayname from LDAP).
How do i get it into datatables?
Thanks a lot for your help.
In what way does it not accept it? Is there an error or something else?
Allan
No, no error message.
The ajax response with the correct value. If i put "alert(axdata)" in line 8, i see the correct value. But the value will not be accepted by datatables. The editor window closes normaly and you see the website with the datatables table, but the new value is not in there.
Is this the correct syntax?
editor.field('tname').val( axdata );
Yep, here's an example using that - http://live.datatables.net/vejolizo/1/edit
Thank's a lot Colin, it works!
I had to change
editor.field('tname').val( axdata );
into
editor.field('tname').set( axdata );
Odd -
val
should work just the same way asset
when passing in a parameter. Good to hear you've got it working though.Allan
@allan
Hmmm, it seems that
val
is only readable and to insert values you have to useset
.It does with both - I wrote the unit tests See that last example updated here.
But why does
val
not work to set a value for me?Without seeing it, it's hard to say. Are you able to update my test case above to demonstrate that issue?
I find out that
val
takes a lot of time zu proceed. If i useval
in the Code and fill out the needed data in the field and directly press on the "Update" or "New" button, then i will get no results.If i wait around 10 secs. before i press the button i will get an result.
I understand that it's very hard for you to find an resolution without seeing the website. But perhaps you have a hint where i have to look in the code.
I'd say if
field().set()
works stay with that. They are doing the same thing in the code, so it shouldn't be making a difference, and impossible to suggest where to look. If that solution doesn't work, we'd need to see it - either by updating my example (which is showing them both working), or a link to your page.Unfortunately, I can not share the website, as it runs on a corporate intranet and does not have internet access.
I will use
set
as it works with it. I had only wondered whyval
did not work.