How to show data in input field when select data at dropdown in Grocery Crud and Codeigniter - codeigniter

In Grocery Crud and Codeigniter , Basically i want to show data from one table(such as a_tbl) when select data or id_no(id_no will get from a_tbl) in dropdown then Name and current posting data will take in input field from table(such as a_tbl) , Then Designation, Dept and Section will take in input field from three different table (such as desg_tbl, dept_tbl, sect_tbl).
How can i solve it , Please any help me

You can use AJAX.
If you use jquery, you can do something like:
$("#field-ID_No").change(function(){
$.ajax({
'url':'your_controller/get_name_of_id/'+$("#field-ID_No").val(),
'success':function(response){
$("#field-Name").value(response);
}
});
});
Basically, when field-ID_No (the select/combobox) changed, the program will send a request to the server (for example: get_name_of_id/1). Assuming, you have "get_name_of_id" function in the controller that echo-ing a name based on given id, you will get the name as response.
(Sorry if it sounds complicated). And then, the value of field-Name should be changed with that echoed name.
For more information about AJAX and JQuery, you can read https://stackoverflow.com/a/5004276/755319

I have done this what you want, it is really simple complete tutorial is on following link
http://www.grocerycrud.com/forums/topic/1087-updated-24112012-dependent-dropdown-library/
hope you will find it helpful

Related

Default sort for Xpages Dojo Data Grid not working on filtered values

I am trying to implement the DOJO data gird in my application. On load of the xPages I am getting the current user id in a session scope variable and filtering the REST services that supplies the data grid the data from a view, based on the user id. I have used the "keys" property to filter the values so that the current user should be able to see the values only relevant to him in the grid. This is working fine, but when I try to sort the results once the page is loaded it starts displaying blank values and sort does not work. I have made sure that the columns I require to sort are also made sorted for the back-end view by checking the "Click on column header to sort" option in the view. Still I am unable to get the sorting working for columns. Please let me know if there is a work-around for this problem or am I doing or not doing something for the default sort not to work as expected.
Nash, I have had similar issues with the blank rows as you describe. I think the blanks lines are rows that don't match the keys. Here are my tips for fixing this. The issue I think is not with your grid but your Rest service.
Use a viewJsonService type of rest service
Use a category filter instead of keys
Make your category filter code similar to mine below. This will ensure that you don't show documents to someone who shouldn't see them. When the category is null, the Rest service will show all documents. This isn't causing the blank lines, but is a best practice IMO.
var category:String = lineItemBean.getThisUNID();
//wherever your category comes from, maybe session.getUserName() in your case
if(category == null){
return "show nothing"
} else {
return lineItemBean.getThisUNID();
}
I hope this helps. My guess is that this will fix your sorting issues as well.

0 getting inserted into table fields

I have a website done using code igniter. My issue is in the registration form where '0' values getting inserted into my database table columns without any known submission. i can view the IP address from which the registrations comes. Since java script validations are given, also one field is readonly in my form, am surprised how '0' get dumped into my table fields. This dummy registration happen 2 or 3 at a time, then after few hours may be another insertion. can someone help to deal with it.
I have implemented same functionality in which required ajax call to save data.
I suggest to implement server side validation for the ajax call and check the value of form posted then validate and insert only entry with valid value or not null.
The issue is most likely the way you are sending your data from AJAX. The most accurate way that works for me is the following:
var url = "http://...";
var dataToSend= {'company':company, 'dateFrom':dateFrom, .....};
$.post(url, dataToSend, function(data) {
alert(data);
});

creating a form field populated by a relationship in Laravel 4

I am trying to build a form for a Happening. The Happening references a Places table by place_id.
e.g. happening "OktoberFest" has a place_id 123 which corresponds in table Places to München
These are the relationships declared in the models:
For model Place:
public function happenings()
{
return $this->hasMany('Happening');
}
For model Happening:
public function place()
{
return $this->belongsTo('Place');
}
model Happening has a place_id field linking it to Place.
I am also using {{Form::model($happening, array('route' => array('happenings.update', $happening->id)...}} as form opening
Problem 1: how to create a {{Form::text('......')}} that will be properly prefilled with München when editing the happening Oktoberfest ?
Problem 2: I was trying to get that field to work as an ajax autosuggest (i.e. starting to pull suggestions from the Places table as soon as 3 characters have been entered). I have checked a few implementations but they don't seem to mix correctly with Problem 1
To try and solve Problem 1, I have tried the solution here
Laravel 4 Form builder Custom Fields Macro
but I was unable to make it work.
Long question, it's my very first on stack overflow, please be patient :)
If a Happening is linked to Place via the column 'place_id' you have to supply an id to save in your model/table.
There are a couple of ways that I can think of:
make a list of availble Places in a radio of select, the name will be 'place_id', the value the id of the Place en something like title for the value.
instead of displaying radio's or a select a textfield with autocomplete is a great solution if you got a lot of places. I won't go into detail how to implement it but the general idea is to autocomplete the typed in placename and on selection of that place to put the id of that place in a hidden field named 'placed_id'
After saving the form save your model with the posted place_id
(and check that id if it's valid and existing, never trust user input )

problem with 'datatable' jquery plugin and two table (ajax related)

i have two tabs that their content loads by ajax. both have a table in their content. i want to apply 'datatable' jquery plugin to both table. tables have the same id because they are create by a function.but their rows are different.
datatable plugin is applied to first tab table well but on the second one give this error:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster)."
i use "bDestroy":true in datatable plugin define.but in this way the plugin doesn't show in second table.
would you help me?
Your problem is that both tables have the same ID, which is invalid HTML. When you try to initialize the second Databable, your selector only finds the first table and tries to initialize Datatables on the first table again, which results in the error that you are getting.
You need to change your function to create each table with a unique ID and initialize each table by its respective ID.
Why not set the Datatables by a className rather than ID then it can apply to both of them?
When retrieving the data you can use something like $('.dataTableStyle').eq(1) to get information from the relevant one.
I'm using mvc3 and my problem was with initializing a dataTable in a view, then rendering a partial view with another dataTable. The issue was not in the id's of the 2 tables, but in the way the partial views get rendered in the framework. In my case, I had to move the script, or reference to the script, into the view that hosts the partial view. I had an issue similar to this using the Google Maps api.
try this code
$(document).ready(function() {
oTable = $('#DataTables_Table_0').dataTable({ //DataTables_Table_0 <-------table id
iVote: -1, //your field name
"bRetrieve":true
});
oTable.fnSort( [ [1,'desc'] ] );
});
use this in function event when you would change your table data
$('#tbl_resultates').dataTable().fnDestroy();
and add
"bRetrieve": true,
in
$('#tbl_resultates').dataTable({

Auto populate city textfield by entering zip and vice versa

I've seen that this question has been posted a couple of times but nothing specific enough for me to use.
I have a form (In a .php file), with a Zipcode and City textfield. I also have a seperate database which holds all zipcodes and cities for my country. (Zipcode in column 1 and city in column 2)
What i would like is that whenever a user inputs either city or zipcode the other field updates/populates automatically based on the database.
I've tried looking for a jquery / ajax solution, but i haven't found one yet.
AJAX can do the trick. You may try something like this: LINK.
I suggest you to use jQuery, it's much cleaner code for AJAX than coding it yourself.

Resources